Skip to content

Queue

@veloxts/queue provides background job processing.

Terminal window
pnpm add @veloxts/queue
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);
},
});
import { dispatch } from '@veloxts/queue';
await dispatch(SendWelcomeEmail, {
userId: '123',
email: 'user@example.com',
});
queuePlugin({
driver: 'sync', // Runs immediately
})
queuePlugin({
driver: 'bullmq',
config: { url: process.env.REDIS_URL },
})
await dispatch(SendWelcomeEmail, data, {
delay: 60_000, // Delay 1 minute
attempts: 3, // Retry 3 times
backoff: {
type: 'exponential',
delay: 1000,
},
});