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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,18 @@ import { DateTime } from 'luxon'
import next from './next'
import parse from './parse'
const MAX_DELAY = 2 ** 31 - 1
class Job {
constructor (schedule, fn) {
const wrapper = scheduledRun => {
if (scheduledRun) {
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._timeout = undefined