Developer ResourcesExtra Resources
BullMQ Job Scheduler
Guide to background job processing with BullMQ in the API runtime.
BullMQ Job Scheduler
BullMQ is used for asynchronous/background processing with Redis.
1. Registered Queues
Queue names are sourced from @happy-shop/jobs (QueueName enum).
Current runtime registration is in:
apps/api/src/services/bullmq/bull.module.ts
Active queues include:
notificationscartordersorders_maintenancemaintenanceorders_reservationsorders_stock_finalizeorders_stock_releaseinventory
Notifications Queue Job Types
The notifications queue (QueueName.NOTIFICATIONS) has exactly two job types (NotificationJob in @happy-shop/jobs):
SEND_EMAIL— transactional auth email (password reset, verify email, account recovery). Producer:AuthEmailService.SEND_OTP— SMS-delivered OTP. Producer:AuthEmailService.
Push-notification jobs (SEND_PUSH, SEND_PROMO_PUSH), batch/promotional email jobs (SEND_PROMO_EMAIL, SEND_EMAIL_BATCH), and the promotional-schedule job (EXECUTE_PROMO_NOTIFICATION_SCHEDULE) have been removed along with Firebase/FCM and the e-commerce transactional notification layer.
2. Service Usage
Use BullService with injected queue tokens.
import { InjectQueue } from "@nestjs/bullmq";
import { Injectable } from "@nestjs/common";
import { QueueName } from "@happy-shop/jobs";
import type { Queue } from "bullmq";
import { BullService } from "@/services/bullmq/bull.service";
@Injectable()
export class ExampleService {
constructor(
private readonly bullService: BullService,
@InjectQueue(QueueName.ORDERS) private readonly ordersQueue: Queue,
) {}
async enqueueOrderCancel(orderId: number, cancelledBy: string): Promise<void> {
await this.bullService.addJob(
this.ordersQueue,
"order.cancel",
{ orderId, cancelledBy, cancelledByActorType: "customer" },
{ priority: 1 },
);
}
}3. Best Practices
- Keep payloads small and serializable
- Use idempotent processors
- Configure retries + exponential backoff
- Set remove-on-complete/fail retention policies
- Log start/success/failure with correlation IDs