taskforcesh / issues

Taskforce.sh issues
6 stars 0 forks source link

A way to remove the "on the hour" behavior of the Repeatable Job #78

Closed gitChristian closed 2 years ago

gitChristian commented 2 years ago

(repost from bullmq issues) I'm wondering if there is a way to remove the "on the hour" behavior of the Repeatable Job specified here.

Adding a job with the repeat option set will actually do two things immediately: create a Repeatable Job configuration, and schedule a regular delayed job for the job's first run. This first run will be scheduled "on the hour", that is if you create a job that repeats every 15 minutes at 4:07, the job will first run at 4:15, then 4:30, and so on.

Use case: I have a queue with jobs that should run every 6 hours. Throughout that time window, many jobs will be added to the queue. Because of this "on the hour" behavior, all the jobs will try to be run at the same time. Is there any way to have them staggered? Thanks!

gitChristian commented 2 years ago

One solution im thinking of is this:

    await refreshQueue.add( id, { data },
      { repeat: { every: minutes * 60 * (800 + <random number 1-400>, } } //800 represents milliseconds
    );

This will create some staggering, but is there something better?

manast commented 2 years ago

This is the wrong repo for BullMQ issues, but I can give you an answer, you can use cron expressions to do this so that you generate the expression in such a way that it is based on the moment the job was added, then you can accomplish staggering.