Async Queue (Redis) — Quickstart
This module provides an abstraction for job queues and drivers. A simple in-memory driver is included for testing and local development.
API (Queue):
Queue.register(name, driver)— register a new driverQueue.get(name?)— get a driver (defaults toprocess.env.QUEUE_DRIVERorinmemory)Queue.enqueue(queue, payload)— enqueue a jobQueue.dequeue(queue)— dequeue next jobQueue.ack(queue, id)— acknowledge a jobQueue.length(queue)— get pending job countQueue.drain(queue)— clear all jobs
Driver interface:
enqueue(queue, payload): Promise\<string>dequeue(queue): Promise\<QueueMessage | undefined>ack(queue, id): Promise\<void>length(queue): Promise\<number>drain(queue): Promise\<void>
Notes:
- The in-memory driver is NOT suitable for production — use Redis or another durable backend for PHASE 1.5 production work.
- Drivers should be registered with
Queue.register('redis', RedisDriver).
Redis Driver (Quick Usage)
- The Redis queue driver stores messages as JSON strings in a Redis list and provides a minimal, reliable surface for enqueue/dequeue operations.
- Configure via
REDIS_URL(e.g.,redis://:password@host:6379). - You can register the driver with
Queue.register('redis', RedisDriver)and then callQueue.enqueue('my-queue', payload, 'redis').
Install Redis driver
bash
zin add queue:redisRabbitMQ Driver
Install:
bash
zin add queue:rabbitmqAWS SQS Driver
Install:
bash
zin add queue:sqsNote: This driver uses rPush/lPop semantics; ack() is a no-op for this simple implementation. For visibility timeouts and retry mechanics, implement a processing list (BRPOPLPUSH) and message requeueing.
CI integration
- A GitHub Actions workflow is provided at
.github/workflows/redis-integration.ymlto run the Redis integration test when a Redis endpoint is configured in the repository secrets asINTEGRATION_REDIS_URL. - To enable: add a repository secret
INTEGRATION_REDIS_URLwith a value likeredis://:password@host:6379and the workflow will run automatically on push/pull_request, or you can trigger it manually via "Run workflow" in the Actions tab. - For self-hosted Redis in CI you can use a managed host (Upstash/Redis Cloud) and set the connection URL as the secret.
Integration testing
- Integration tests that exercise a real Redis instance are included under
tests/integration/queue/Redis.integration.test.ts. - To run them locally or in CI, set
REDIS_URLto a reachable Redis instance (e.g.,redis://:password@host:6379). - The integration test is skipped automatically when
REDIS_URLis not set so CI jobs that don't have a Redis dependency will not fail.