Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed and Repeatable parameters together in one Job not working #431

Closed
MurzNN opened this issue Mar 16, 2021 · 7 comments · Fixed by #983
Closed

Delayed and Repeatable parameters together in one Job not working #431

MurzNN opened this issue Mar 16, 2021 · 7 comments · Fixed by #983
Labels
enhancement New feature or request

Comments

@MurzNN
Copy link

MurzNN commented Mar 16, 2021

I need to use both delay and repeat parameters in BullMQ Job instance, for make a delay of first job execution, so I compose code like this:

import { Queue, QueueScheduler } from 'bullmq';

const myQueueName = 'foo'
const myQueue = new Queue(myQueueName);
const myQueueScheduler = new QueueScheduler(myQueueName);

async function addJobs(){
    await myQueue.add('job_delayed', {}, {
        delay: 20000,
        repeat: {
            every: 5000,
            limit: 10
        }
    });
}

await addJobs();

let timeStart = new Date();

import { Worker } from 'bullmq'

const worker = new Worker(myQueueName, async job => {
    console.log('secs from start: ' + (new Date() - timeStart) / 1000 + ' - ' + job.name);
});

And the problem is that the first job launch is happens at 5 sec delay, instead of 20 sec, here is output:

$ node ./index.js
secs from start: 4.735 - job_delayed
secs from start: 9.654 - job_delayed
secs from start: 14.67 - job_delayed
secs from start: 19.691 - job_delayed
secs from start: 24.71 - job_delayed
secs from start: 29.732 - job_delayed
@MurzNN
Copy link
Author

MurzNN commented Mar 16, 2021

If I comment-out the repeat section:

async function addJobs(){
    await myQueue.add('job_delayed', {}, {
        delay: 20000,
        // repeat: {
        //     every: 5000,
        //     limit: 10
        // }
    });
}

delay works well:

$ node ./index.js
Starting worker
secs from start: 20.022 - job_delayed

@manast
Copy link
Contributor

manast commented Mar 17, 2021

The delay cannot be combined with "every", we should definitively throw an exception to avoid misunderstandings. However there is the "startDate" property that you can use, however it only works with "cron" expressions, not with "every". Maybe this is a workaround for your case.

@manast manast added the enhancement New feature or request label Mar 17, 2021
@MurzNN
Copy link
Author

MurzNN commented Mar 18, 2021

Thanks for clarification, I need the job that will be started, for example, at 3 hours after start, and repeats unlimited time every 10 minutes. If this cannot be combined, it's better to implement this in worker logic, or you can recommend some better solution?

@manast
Copy link
Contributor

manast commented Mar 18, 2021

Why cant you use a cron expression like * */10 * * * * ?
https://www.npmjs.com/package/cron-parser

@MurzNN
Copy link
Author

MurzNN commented Mar 18, 2021

Why cant you use a cron expression like * */10 * * * * ?
https://www.npmjs.com/package/cron-parser

Because I need the startup delay for 3 hours, together with */10

@manast
Copy link
Contributor

manast commented Mar 18, 2021

I wrote above you can use "startDate" too.

@MurzNN
Copy link
Author

MurzNN commented Mar 18, 2021

Yeah, thanks, this is the solution too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants