bullmq icon indicating copy to clipboard operation
bullmq copied to clipboard

Promoting a recurring job does not schedule the next job

Open jasonkim opened this issue 5 years ago • 9 comments

I'm not sure if this is the expected behavior. If I were to promote a recurring job, it should run it and then ideally queue the next job.

jasonkim avatar Jul 30 '20 01:07 jasonkim

It should work, since a recurring job is waiting as a delayed job, can you provide a test where this does not hold?

manast avatar Jul 31 '20 07:07 manast

Finally got around to create a simple case.

import ioredis from 'ioredis'
import bullmq from 'bullmq'
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
async function test() {
  const { Queue, QueueScheduler, Worker, Job } = bullmq
  const connection = new ioredis()

  // bull-board
  const { setQueues } = bullboard

  const testq = new Queue('test', {connection})
  testq.add('recurring', {}, { repeat: { cron: '* * * * *' } })
  setQueues([testq])
  new QueueScheduler('test')

  new Worker('test', async job => {
    console.log(Date())
    console.log(job.id)
  })

  await sleep(90000)
  console.log(await testq.getDelayedCount())
  const jobs = await testq.getDelayed()
  const job = jobs[0]
  // console.log(job)
  job.promote()
  console.log("Promoted")
  await sleep(1000)
  console.log(await testq.getDelayedCount())

}
test()

I'm using a bull-board, but you can comment that out as that is not very important. It should print the datetime and jobid every time the worker runs, but after promotion, it stops. I've put in sleep function, but that's not very important and just shows that the recurring job works.

jasonkim avatar Aug 03 '20 07:08 jasonkim

Also noticed this issue. Promoting the job would run the process function, but the job would not be rescheduled afterwards. I had to work around this by essentially duplicating the data of the recurring job into a new job and adding that to the queue.

Khauri avatar Aug 04 '20 15:08 Khauri

I have reproduced this issue and know exactly why it happens, but I need some time to fix it.

manast avatar Aug 08 '20 08:08 manast

Thanks! In the meantime I've just done this and it works for my purposes:

if(/^repeat:/.test(job.id)) {
  await queue.add(job.name, job.data);
} else {
  await job.promote();
}

But I do have a small question. When promoting a repeating job, say one that runs hourly with the next execution time being 10am, is the intended behavior to keep the scheduled time for the job as its next execution time (still 10am), or would it be to schedule it for the next hour afterwards (11am?).

Khauri avatar Aug 08 '20 11:08 Khauri

@Khauri it will be scheduled to the next run.

manast avatar Aug 10 '20 16:08 manast

I had the same issue. I promoted a repeating job with bull board. It disappeared from the delayed list and never came back.

janfietz avatar Nov 20 '20 15:11 janfietz

Yeah, it's related to this line https://github.com/taskforcesh/bullmq/blob/master/src/commands/promote-5.lua#L20, where job is deleted from delayed list

roggervalf avatar May 09 '21 23:05 roggervalf

@fgozdz I think this issue has been resolved some time ago, specially with the new job scheduler, could you please verify that it works now with a new test case so that we can close this issue?

manast avatar Nov 26 '24 09:11 manast

I'm currently experiencing this issue with the latest version (5.56.1). I have a simple every 900s job scheduler. If I promote the delayed job from the Taskforce dashboard no new delayed job is created.

EmilEriksen avatar Jul 04 '25 07:07 EmilEriksen

I actually have another service running an older version (5.52.2) where this does not happen.

EmilEriksen avatar Jul 04 '25 07:07 EmilEriksen

@EmilEriksen actually I do not think the delayed job will be created directly, it will promote the current delayed job to wait status, and as soon as it is picked up by a worker a new delayed job will created instead.

manast avatar Jul 04 '25 14:07 manast

@manast From what I can tell in the UI no new job is ever created even after the promoted job is processed. I can still see the scheduler under "Schedulers" but in Next job it just says X minutes ago.

EmilEriksen avatar Jul 04 '25 14:07 EmilEriksen

@EmilEriksen yes, I can reproduce an issue. A job that is promoted, when processed will not generate a new delayed job.

manast avatar Jul 04 '25 14:07 manast

in other words, it will break the iterations... we will start working on a fix now that we can reproduce it.

manast avatar Jul 04 '25 14:07 manast

The fix is coming in this PR: https://github.com/taskforcesh/bullmq/pull/2944

manast avatar Jul 07 '25 09:07 manast

:tada: This issue has been resolved in version 5.56.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 10 '25 01:07 github-actions[bot]