Queue
@veloxts/queue provides background job processing.
Installation
Section titled “Installation”pnpm add @veloxts/queueDefine Jobs
Section titled “Define Jobs”import { defineJob } from '@veloxts/queue';import { z } from '@veloxts/velox';
export const SendWelcomeEmail = defineJob({ name: 'send-welcome-email', schema: z.object({ userId: z.string(), email: z.string().email(), }), handler: async ({ data, progress }) => { await progress(50); await sendEmail(data.email, 'Welcome!'); await progress(100); },});Dispatch Jobs
Section titled “Dispatch Jobs”import { dispatch } from '@veloxts/queue';
await dispatch(SendWelcomeEmail, { userId: '123', email: 'user@example.com',});Drivers
Section titled “Drivers”Sync (Development)
Section titled “Sync (Development)”queuePlugin({ driver: 'sync', // Runs immediately})BullMQ (Production)
Section titled “BullMQ (Production)”queuePlugin({ driver: 'bullmq', config: { url: process.env.REDIS_URL },})Job Options
Section titled “Job Options”await dispatch(SendWelcomeEmail, data, { delay: 60_000, // Delay 1 minute attempts: 3, // Retry 3 times backoff: { type: 'exponential', delay: 1000, },});