Skip to main content

Adding a queue or job

  1. Add the queue name to APP_BULL_QUEUES in src/app/enums/app.enum.ts when it is a shared queue. WhatsApp catalog is the exception that is not in the enum. Prefer the enum.
  2. BullModule.registerQueue in the producer module and in WorkerModule.
  3. Put the processor under src/workers/processors, extending BaseQueueProcessor when you want Sentry on the terminal failure.
  4. Inside the processor, enter runWithTenantContext with the tenant on the job payload.
  5. Choose attempts, backoff, and whether jobId dedupes. Default retention used by several queues is 3 attempts and exponential backoff of 2 seconds. Webhook uses 8 and 5 seconds. Do not assume the default if you pass nothing. Read DEFAULT_QUEUE_RETENTION_OPTIONS.
  6. Throw if you want Bull to retry. Returning after a catch marks the job complete.
  7. Register the queue on Bull Board only if operators should see it. The current board route is /admin/queues and does not list every queue.

Schedulers belong on the scheduler process (src/main.scheduler.ts / scheduler module). PartitionMaintenanceService is the exception that is loaded by the worker. Do not add a second midnight cron that only logs. MidNightScheduleWorker already does that and performs no business work.

Enqueue from a request only after you accept that a crash between commit and queue.add drops the job. If the work must not be lost, write an outbox row in the transaction and let a listener enqueue.