Node.js + SQLite · source included
A small job queue that survives a restart.
Persistent jobs, worker leases, bounded retries and dead-letter recovery in a dependency-free, single-host reference implementation.
How a job moves
Each claim gets a fresh token. An expired worker cannot acknowledge a job after another worker takes over. A failed job waits before retrying; exhausted jobs can be inspected and explicitly requeued.
Run it locally
Extract the ZIP and run these commands from its folder. No installation, credentials or network access are required.
node --test queue.test.mjs node example-worker.mjs example.sqlite node example-worker.mjs example.sqlite
The first example run completes one uppercase-text job. The second reports No due job. The persisted idempotency key prevents it from creating another copy.
What was checked
- Repeated enqueue, payload mismatch and delayed availability.
- Lease exclusion, expired-worker fencing and successful completion.
- Exponential backoff, retry caps, exhaustion and manual requeue.
- Closing and reopening a real SQLite file.
- Four independent Node processes competing for one job; exactly one receives it.
Where the sample stops
Execution is at least once. A job can repeat an external effect if its worker dies before acknowledgment. The job handler must make those effects idempotent; lease tokens protect queue state only.
There is no heartbeat, hosted worker or production integration. Multiple hosts, network filesystems, crash or power-loss durability, load limits, backups and migration are not validated. See the README for the exact assumptions.