diff --git a/@xen-orchestra/cron/src/index.js b/@xen-orchestra/cron/src/index.js index dae5c62e8..c599a7297 100644 --- a/@xen-orchestra/cron/src/index.js +++ b/@xen-orchestra/cron/src/index.js @@ -9,7 +9,7 @@ class Job { if (scheduledRun) { fn() } - this._timeout = setTimeout(wrapper, schedule.next() - Date.now(), true) + this._timeout = setTimeout(wrapper, schedule._nextDelay(), true) } this._fn = wrapper this._timeout = undefined @@ -44,6 +44,11 @@ class Schedule { } return dates } + + _nextDelay () { + const now = DateTime.fromObject(this._dateTimeOpts) + return next(this._schedule, now) - now + } } export const createSchedule = (...args) => new Schedule(...args)