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

Repeatable 1 hour interval not working #1145

Closed
c4dx opened this issue Mar 21, 2022 · 5 comments
Closed

Repeatable 1 hour interval not working #1145

c4dx opened this issue Mar 21, 2022 · 5 comments

Comments

@c4dx
Copy link

c4dx commented Mar 21, 2022

Hi. I cant manage to setup a 1 hour repeat-interval with the cron field.

I've used the cron-parser mentioned at https://docs.bullmq.io/guide/jobs/repeatable to test my notation.

var parser = require('cron-parser')
var interval = parser.parseExpression('0 0 0/1 1/1 * ?')
console.log(interval.next().toString())
console.log(interval.next().toString())
console.log(interval.next().toString())

Which gives the following (correct) result:

"Thu Mar 17 2022 10:00:00 GMT+0100 (Central European Standard Time)"
"Thu Mar 17 2022 11:00:00 GMT+0100 (Central European Standard Time)"
"Thu Mar 17 2022 12:00:00 GMT+0100 (Central European Standard Time)"

Trying to use it in my project like this:

await this.queue.add('my-job', {}, {
    attempts: 1,
    repeat: {
        cron: '0 0 0/1 1/1 * ?'
    },
    timeout: 1000 * 60 * 10
})

//....

private async run(job: Job) {
    //...
    console.log('JOB STARTING!', new Date().toLocaleString())
    await runMyJob()
}

Which shows the following in the console:

JOB STARTING! 3/17/2022, 8:52:00 AM
JOB STARTING! 3/17/2022, 8:53:00 AM
JOB STARTING! 3/17/2022, 8:54:00 AM
JOB STARTING! 3/17/2022, 8:55:00 AM

It is running every minute instead of every hour. Googling for examples was confusing as there are 5-field cron examples as well as 6-field examples.

I also tried the 5-field syntax with 0 * * * * which also didnt worked. Is this a bug or am I just doing something wrong in here?

Thanks

@manast
Copy link
Contributor

manast commented Mar 21, 2022

For syntax, examples and tests please refer to cron-parser which is the library we use: https://www.npmjs.com/package/cron-parser

@c4dx
Copy link
Author

c4dx commented Mar 21, 2022

For syntax, examples and tests please refer to cron-parser which is the library we use: https://www.npmjs.com/package/cron-parser

Ok.......
Have you noticed that:

  • I've used exactly the same cron-parser you mentioned
  • The parser gives out the expected interval (1 hour)
  • bullmq somehow picks up another interval (1 minute)

I dont think that the cron-parser is a problem in here.
I assume either I am the problem (with bullmqs syntax), or there's a bug with bullmq itself.

Am I wrong?

@manast
Copy link
Contributor

manast commented Mar 21, 2022

Sorry, I did not read your reference to cron-parser. I am quite sure this works. You are not providing a complete case, maybe what you are seeing are old repeatable jobs. I just wrote a super quick test and it seems to work:

const { Worker, Queue } = require("bullmq");

const queue = new Queue('my-job', {
  connection: {
    host: "localhost",
  },
});

const worker = new Worker(
  "my-job",
  async (job) => {
    console.log(`Process started for Job ${job.id}`);
  },
  {
    connection: {
      host: "localhost",
    },
  }
);

queue.add(
  "my-job",
  {},
  {
    attempts: 1,
    repeat: {
      cron: "0 0 0/1 1/1 * ?",
    },
    timeout: 1000 * 60 * 10,
  }
);

image

image

@c4dx
Copy link
Author

c4dx commented Mar 22, 2022

Hmm thats weird. Thanks for trying out on your side.

I'll try to comment out most of the stuff around my job-related things and see if there's anything interfering with it.

@c4dx
Copy link
Author

c4dx commented Mar 22, 2022

Turns out after changing the cron-interval and restarting the server, bullMQ restored the old job from the redis database (which was continuously running in a docker container).

Sorry for bothering you.
Have a nice day!

@c4dx c4dx closed this as completed Mar 22, 2022
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

2 participants