Merged
Conversation
- Add Job struct with full lifecycle support (pending, running, completed, failed, dead) - Add status and priority constants - Implement job validation and state transition methods - Add Queue model with statistics and health scoring - Support for scheduled jobs, retries, and max attempts
- Add full PostgresBackend implementation using pgx/v5 - Implement atomic job reservation with FOR UPDATE SKIP LOCKED - Add embedded SQL migrations for jobs table - Create optimized indexes for queue operations - Support priority-based job ordering - Add automatic DLQ promotion on max attempts - Include migration runner with golang-migrate
- Add full RedisBackend implementation using go-redis/v9 - Implement atomic operations with Lua scripts - Use sorted sets for time-based job scheduling - Add distributed job reservation with status tracking - Create Lua scripts for reserve and nack operations - Support efficient queue statistics gathering - Store jobs as Redis hashes with status sets
- Add unit tests for Job and Queue models (11 test cases) - Add integration tests for PostgresBackend (13 test scenarios) - Add integration tests for RedisBackend (13 test scenarios) - Test concurrent job reservation to prevent double-processing - Test automatic DLQ promotion and retry logic - Test priority ordering and scheduled job handling - All tests passing with 100% method coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.