-
Notifications
You must be signed in to change notification settings - Fork 1
Queueing Model
Each command is represented by a set of queues:
- Pending queue: list of IDs available for claim.
- In-progress queue: list of IDs currently leased.
- Delayed queue: ZSET of IDs with
visibleAtas score. - Dead-letter queue: list or ZSET for tasks that exceeded
maxAttempts.
Delayed visibility is used for retries. The delayed ZSET score is visibleAt. Claim-time repair moves due tasks from delayed to pending.
Priority is implemented using multiple pending lists per priority tier (0..9). The claim algorithm checks higher tiers first. This matches Dyno Queues support for priority queues while keeping list operations O(1).
Alternative: store ready tasks in a ZSET with score (priority, sequence) but that increases pop complexity to O(log n).
- A claim moves one ID from pending to in-progress using
RPOPLPUSH. - A lease key is set with TTL
leaseSecondsand valueworkerId. - The task record is updated to
IN_PROGRESS,workerId, andleaseUntil.
Acknowledgement is equivalent to result submission. On success the task is removed from in-progress, the lease is cleared, and status is set to COMPLETED or FAILED. This follows the Dyno Queues model where unacknowledged messages are requeued after a timeout.
If the lease expires before completion or a worker sends nack, the task is retried. attempts is incremented on retry. If attempts >= maxAttempts, the task is moved to the dead-letter queue and marked FAILED with error=MAX_ATTEMPTS. Otherwise the task is moved to the delayed queue using the computed backoff delay.
When idempotencyKey is provided, the service stores a mapping of idempotencyKey -> taskId with TTL equal to the retention window. Subsequent requests with the same key return the existing task.