1
    import { Queue, Worker, Job } from 'bullmq';

const myQueue = new Queue('firstjob', { connection: redis });
    import { autorunJobs } from './processes/job.process';
    
async function addQueue() {
    await myQueue.add(
        'autoclosejob',
        {
            repeat: {
                cron: '* * * * *'
            },
        },
    );
}

addQueue();

const worker = new Worker('firstjob', async (job: Job) => {
    console.info('Started.');
   await autorunJobs();
    console.info('Closed.');
    //return true;
}, { connection: redis });
worker.run();

When I run this code, it executes successfully at once. But after I wait for the worker to run it again in the next minute but it doesn't. What I see is only one-time console.log output.

Following are one-time output logs:

Tue, 10 May 2022 12:21:12 GMT | IDM Service | INFO |    Started.
dta = "some data"
Tue, 10 May 2022 12:21:12 GMT | IDM Service | INFO |      Closed.

I want this output after every minute.

What I am doing wrong?

Biku7
  • 450
  • 6
  • 16
  • (1) You might want to validate your cron expression. (2) have you added a QueueScheduler for your queue? – mauris May 14 '22 at 04:04

1 Answers1

0

So the important thing here is to ask yourself what exactly a repeatable job is. This will solve your issue. To answer that question in short:

A repeatable job is in essence a delayed job. What does this entail? A delayed job needs a QueueScheduler, not a normal Queue. That's most likely why your job does not repeat after the first time.

Docs that provide more info: https://docs.bullmq.io/guide/jobs/repeatable

I hope this answers your question and for people who may run into the same issue in the future.