Scheduling

Scheduler modes

Cronbake can wait for each tick with one precise timer, or check the clock at a fixed interval. The default is the better choice for almost every app.

On this page
tick duecalculatedtimeoutsone timer, set for the exact delayrunpollingevery 1000 msrunlate by up to one interval

Calculated timeouts

This is the default. Each job works out when its next tick is due and sets a single setTimeout for exactly that long. It fires on time and does nothing in between, however many jobs you have.

Polling

Each job runs a setInterval and checks the clock on every interval. When a tick is due, the run starts at the next check, so it can be up to one interval late.

const baker = Baker.create({
  schedulerConfig: {
    useCalculatedTimeouts: false,
    pollingInterval: 1000,
  },
});

For a job created without a baker, pass the same settings as the second argument.

const job = Cron.create(
  { name: "poll", cron: "@every_minute", callback },
  { useCalculatedTimeouts: false, pollingInterval: 5000 },
);

pollingInterval defaults to 1000 ms. It has to be greater than 0 and no more than 2,147,483,647 ms, or creating a job throws.

Keep the interval shorter than the schedule

After a run starts, the next tick is worked out from the current time. If your interval is longer than the gap between ticks, the ticks in between are lost. A job on * * * * * * polled every 2,500 ms runs about once every 2.5 seconds, not every second.

Very long delays

setTimeout can’t wait longer than 2,147,483,647 ms, or about 24.8 days. When a job’s next tick is further away than that, it switches to polling on its own at the configured pollingInterval. You don’t need to do anything, and it keeps polling for as long as the job stays scheduled. If that job has an exact time to hit, it can be up to one interval late, like any polling job.

Choosing

Stay on calculated timeouts unless you have a specific reason not to. They’re more accurate and do less work. Polling is there for environments where you’d rather have one regular wake-up than a long timer, and even then a one-second interval is usually plenty.

esc

Try overlap, restore or timezone.