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

[Question] How to run a repeatable job immediate? #1239

Closed
tiaod opened this issue Mar 11, 2019 · 14 comments · May be fixed by #1422
Closed

[Question] How to run a repeatable job immediate? #1239

tiaod opened this issue Mar 11, 2019 · 14 comments · May be fixed by #1422

Comments

@tiaod
Copy link

tiaod commented Mar 11, 2019

Agenda has a option to skip the immediate run:
https://github.com/agenda/agenda#manually-working-with-a-job

options.skipImmediate: true | false (default) Setting this true will skip the immediate run. The first run will occur only in configured interval.

In Bull, a repeatable job will skip the immediate run by default. How to not skip the immediate run?

@manast
Copy link
Member

manast commented Mar 11, 2019

you could add one normal job and that will execute as soon as possible, not sure if that does what you want?

@tiaod
Copy link
Author

tiaod commented Mar 12, 2019

I'm trying to add some repeatable job when server started. eg refreshAccessToken removeOldUsers etc. Bull is smart enough not to add the same repeatable job if the repeat options are the same, so I can restart my server as many as I want without worried about runing the repeatable job too often.
If I add one normal job and that will execute as soon as possible when server startup, it will run every time when I restart my server.

@bdrtsky
Copy link

bdrtsky commented Jul 30, 2019

I am surprised there's no way to do that natively. I also need to start repeatable job right away and then repeat it with cron interval. How to do that safely?

@HugoPoi
Copy link

HugoPoi commented Aug 10, 2019

I'm working on it but it's not simple to do, I even identified a "bug" when you do queue.add(repeatableJob) then you do a job.promote(), the job is reschedule 2x times window later not one.

@manast
Copy link
Member

manast commented Aug 11, 2019

So just to clarify why repeatable jobs work they way they work: the repeatable interval is moved so that the repetition always happen in the exact timestamp. Imagine dividing the time into evenly spaced bins, and the repetitions can only happen on those bins. The reason for this is to avoid all kind of hazards that could otherwise happen. By doing it this way, and having a specific jobId for every bin, we guarantee that jobs will only be processed once per repetition no matter what.

@HugoPoi
Copy link

HugoPoi commented Aug 11, 2019

So in my PR I just set the first timestamp to the previous iteration not the next. So behavior will be the same except the first job will be not space out of the good time amount of the second job.

@niftylettuce
Copy link

You should close this issue, as this is pretty easily possible:

queue.add(null, { repeat: false })

@niftylettuce
Copy link

Also for anyone interested, I have a pretty advanced queue setup with Bull in https://forwardemail.net source code at https://github.com/forwardemail/forwardemail.net (based off my work with https://lad.js.org and https://github.com/ladjs/bull).

@HugoPoi
Copy link

HugoPoi commented May 26, 2020

You should close this issue, as this is pretty easily possible:

queue.add(null, { repeat: false })

Can you elaborate your response to the problem ? And please don't post ads on issues.

@niftylettuce
Copy link

It's not an ad, it's literally a link to how we solved this. Look at the source code for Forward Email:

https://github.com/forwardemail/forwardemail.net/blob/master/bull.js#L44-L52

Here you can see we have a recurring job that properly is emptied on boot, then added as a recurring job, and then added as a normal job through the code I shared here #1239 (comment)

@delivey
Copy link

delivey commented Feb 6, 2023

Any updates on this?

Feel like this is a pretty big issue.

@manast
Copy link
Member

manast commented Feb 6, 2023

@delivey this is possible in BullMQ using the "immediate" option in repeat: https://api.docs.bullmq.io/interfaces/RepeatOptions.html#immediately
We are not backporting new features to Bull anymore.

@manast manast closed this as completed Feb 6, 2023
@dberardo-com
Copy link

what happened to the "immediate" option?

@manast
Copy link
Member

manast commented Jul 20, 2023

The link has changed: https://api.docs.bullmq.io/interfaces/v4.RepeatOptions.html#immediately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants