-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments
you could add one normal job and that will execute as soon as possible, not sure if that does what you want? |
I'm trying to add some repeatable job when server started. eg |
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? |
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. |
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. |
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. |
You should close this issue, as this is pretty easily possible:
|
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). |
Can you elaborate your response to the problem ? And please don't post ads on issues. |
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) |
Any updates on this? Feel like this is a pretty big issue. |
@delivey this is possible in BullMQ using the "immediate" option in repeat: https://api.docs.bullmq.io/interfaces/RepeatOptions.html#immediately |
what happened to the "immediate" option? |
The link has changed: https://api.docs.bullmq.io/interfaces/v4.RepeatOptions.html#immediately |
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?
The text was updated successfully, but these errors were encountered: