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

[Documentation Issue] Job Schedulers immediately repeat option is unclear. #3084

Open
Chee7ah opened this issue Feb 18, 2025 · 2 comments
Open

Comments

@Chee7ah
Copy link

Chee7ah commented Feb 18, 2025

Documentation: https://docs.bullmq.io/guide/job-schedulers/repeat-options#immediately

When you use the every option in BullMQ, it schedules jobs based on fixed time intervals, which might seem a bit counterintuitive initially.
...
For example, if you set the job to repeat monthly, normally it would wait to start until the first second of the next month. If you add the job mid-month, it would not start until the beginning of the following month. Using immediately ensures the first instance of the job runs as soon as it’s added, bypassing the wait until the scheduled interval begins.

Then we have the example:

await myQueue.upsertJobScheduler(
  'immediate-job',
  {
    every: 86400000, // once a day
    immediately: true, // execute the first one immediately
  },
  {
    name: 'instant-job',
    data: { message: 'Immediate start' },
  },
);

Running the above code results in the Using option immediately with every does not affect the job's schedule. Job will run immediately anyway. warning, coming from here:

if (repeatOpts.immediately && repeatOpts.every) {
console.warn(
"Using option immediately with every does not affect the job's schedule. Job will run immediately anyway.",
);
}

This is clearly contradicting what the documentation says.

What I wanted to do is to schedule a repeating job that runs now and then 24 hours later and another 24 hours later and so on.
It seems like having the below code accomplishes this goal (at least running this, my job ran immediately), even though according to the documentation, this would first run at the first second of the next day.

await myQueue.upsertJobScheduler(
  'my-job',
  {
    every: 86400000, // once a day
  }
);

  1. Is my experimental understanding correct, that every causes the job to run now and repeats after every interval?
  2. If so, can the documentation be updated to reflect the actual behavior?
@manast
Copy link
Contributor

manast commented Feb 19, 2025

We deprecated "immediately" on repeat recently but have not yet updated the documentation, thank you for posting this to remind me. The current behaviour is as if immediately is always true, if you need a different behaviour you can use the much more flexible cron expressions or custom expressions.

@robincsamuel
Copy link

  • Is my experimental understanding correct, that every causes the job to run now and repeats after every interval?

@manast Could you please clarify this as well? As per the documentation, every should be running every x seconds. For example, if it's 60000, then the start of every minute. However, for me it's working like an interval; when the job is added at 00:00:15, the next execution is at 00:01:15 instead of 00:01:00.

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

No branches or pull requests

3 participants