Queue migrations
Move supported jobs between registered queues and Redis deployments with deliberate safety limits.
Before enabling migrations#
Migrations move queue data and can affect processing. Protect the API with an operator-only guard, test with disposable queues, and review both Redis deployments before starting. Enabling migrations grants access to queue and cache migration routes, not only read-only previews.
Waiting and delayed jobs are the default states. Failed jobs are opt-in and become new waiting jobs on the target: BullMQ does not provide a supported way to recreate their failed state. Flow and repeatable jobs are rejected, as are active source jobs.
Register source and target#
This example monitors the normal emails queue through Nest DI and explicitly registers a same-named queue on old Redis. It assumes BullModule already registers the current queue and the application provides AdminGuard.
import { Queue } from 'bullmq';
import { QueuebertModule } from '@queuebert/nest';
import { AdminGuard } from './admin.guard';
const oldConnection = { host: 'old-redis.internal', port: 6379 };
const oldEmailQueue = new Queue('emails', { connection: oldConnection });
export const monitoring = QueuebertModule.forRoot({
redis: [
{ id: 'current', label: 'Current Redis' },
{ id: 'old', label: 'Old Redis', connection: oldConnection },
],
queues: [
{ name: 'emails', redis: 'current' },
{ name: 'emails', queue: oldEmailQueue, statsKey: 'emails-old', redis: 'old' },
],
auth: { guards: [AdminGuard] },
endpoints: ['metrics', 'migrations'],
});Add monitoring to your Nest module's imports. Close the directly constructed oldEmailQueue during application shutdown. statsKey separates the queue entries; the Redis IDs identify their deployments.
Preview first#
Preview is a read operation, not an instruction to start moving jobs:
curl --fail --get \
-H "Authorization: Bearer $QUEUEBERT_TOKEN" \
--data-urlencode 'sourceQueue=emails' \
--data-urlencode 'targetQueue=emails' \
--data-urlencode 'sourceRedis=old' \
--data-urlencode 'targetRedis=current' \
--data-urlencode 'states=waiting,delayed' \
http://localhost:3000/admin/queue/migrations/previewUse actual BullMQ queue names for sourceQueue and targetQueue, not their statsKey aliases; the Redis IDs distinguish this example's same-named queues. Inspect counts and destination settings. Raw job payloads in preview samples are redacted by default. includeJobDataInMigrationPreview: true opts in to payloads; leave it off unless authorized clients need them. Execution still reads and copies original job data.
Execute with limits#
Use POST /migrations/start for background execution, or POST /migrations/execute to wait for the result. Both take source/target parameters in the query string. Apply a conservative limit, batchSize, and delayMs, then monitor the returned migration ID through GET /migrations/:migrationId.
Background migrations require registered source and target queues. Pausing or cancelling a migration is not a rollback of jobs already moved. Inspect the source and target before retrying any interrupted operation.
Pause and crash behavior#
The migration path takes a distributed source-queue lease and pauses both queues. It preserves job IDs, options, and timestamps, and restores each queue's previous pause state after a clean exit.
A process crash intentionally leaves queues paused rather than risk concurrent processing. After inspecting both Redis instances, an operator must explicitly resume queues. Do not assume a restart automatically recovers or rolls back a migration.
Background progress is process-local and retained for one hour. Use a single long-lived Queuebert instance for a migration, and keep subsequent progress/control requests on that instance. Restarting it or routing requests to another replica loses access to that in-memory progress record.
Managed caches#
Cache migration routes operate on caches registered through processor getCacheConfigs() metadata. They share the migrations capability. Use /cache/list and /cache/migrations/preview to inspect registered targets before starting; do not assume queue migration state semantics apply to arbitrary cache data.