fix(cron): handle setTimeout max delay (#45)

This commit is contained in:
Julien Fontanet
2018-02-06 15:41:19 +01:00
committed by GitHub
parent 867c9ea66c
commit 9c7c030b00

View File

@@ -3,13 +3,18 @@ import { DateTime } from 'luxon'
import next from './next' import next from './next'
import parse from './parse' import parse from './parse'
const MAX_DELAY = 2 ** 31 - 1
class Job { class Job {
constructor (schedule, fn) { constructor (schedule, fn) {
const wrapper = scheduledRun => { const wrapper = scheduledRun => {
if (scheduledRun) { if (scheduledRun) {
fn() fn()
} }
this._timeout = setTimeout(wrapper, schedule._nextDelay(), true) const delay = schedule._nextDelay()
this._timeout = delay < MAX_DELAY
? setTimeout(wrapper, delay, true)
: setTimeout(wrapper, MAX_DELAY)
} }
this._fn = wrapper this._fn = wrapper
this._timeout = undefined this._timeout = undefined