Repeat Strategies
"Every" strategy
const { Queue, Worker } = require('bullmq');
const connection = {
host: 'localhost',
port: 6379,
};
const myQueue = new Queue('my-repeatable-jobs', { connection });
// Upserting a repeatable job in the queue
await myQueue.upsertJobScheduler(
'repeat-every-10s',
{
every: 10000, // Job will repeat every 10000 milliseconds (10 seconds)
},
{
name: 'every-job',
data: { jobData: 'data' },
opts: {}, // Optional additional job options
},
);
// Worker to process the jobs
const worker = new Worker(
'my-repeatable-jobs',
async job => {
console.log(`Processing job ${job.id} with data: ${job.data.jobData}`);
},
{ connection },
);"Cron" strategy
Custom Strategy
Last updated
Was this helpful?