Phase 1 core domain storage #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phase 1: Core Domain & Storage
🎯 Overview
This PR implements the foundational storage layer for QueueKit, including complete domain models and two production-ready storage backends (PostgreSQL and Redis). This establishes the core infrastructure for job queue operations with support for scheduling, retries, priorities, and dead-letter queues.
📦 What's Included
Core Domain Models (
internal/queue/)Job Model: Complete lifecycle management with UUID-based IDs, JSON payloads, status tracking, and retry logic
pending → running → completed/failed → deadQueue Model: Statistics tracking and health metrics
Backend Interface (
internal/backend/)Enqueue,Reserve,Ack,Nack,MoveToDLQ,ListQueues,ListJobs,GetJob,DeleteJob,ClosePostgreSQL Backend (
internal/backend/postgres/)pgx/v5with connection poolingFOR UPDATE SKIP LOCKED(queue, status, scheduled_at)for fast job reservationstatus,queue,created_at, andtypeRedis Backend (
internal/backend/redis/)go-redis/v9queue:{name})job:{id})status:queue:{name}:{status})reserveScript: Atomically pop and mark job as runningnackScript: Increment attempts and re-enqueue or move to DLQqueueStatsScript: Efficiently gather queue metrics🧪 Testing
Test Coverage
Running Tests
Unit Tests (no external dependencies):
go test ./internal/queue/...PostgreSQL Integration Tests:
export TEST_DATABASE_URL="postgres://user:pass@localhost:5432/queuekit_test?sslmode=disable"
go test -v ./internal/backend/postgres/Redis Integration Tests:
export TEST_REDIS_ADDR="localhost:6379"
go test -v ./internal/backend/redis/## 📊 Statistics
🔍 Implementation Highlights
PostgreSQL Strategy
Best suited for:
Key feature: Uses
FOR UPDATE SKIP LOCKEDto prevent multiple workers from claiming the same job without blocking other workers.Redis Strategy
Best suited for:
Key feature: Lua scripts ensure atomic multi-key operations without round-trip overhead.
✅ Pre-merge Checklist
go build ./...)go test ./internal/queue/...)🚀 What's Next - Phase 2
With the storage layer complete, Phase 2 will implement:
📝 Breaking Changes
None - this is new functionality.
🔗 Related Issues
Implements Phase 1 from PLAN.md
Ready for Review 👀
This PR establishes the foundation for QueueKit's job queue system. Both storage backends are production-ready with comprehensive test coverage and proven concurrency patterns.