fix(cron): disallow jobs executing twice within scheduling precision
This commit is contained in:
parent
413e436c61
commit
bc74c9ef10
12
src/Cron.hs
12
src/Cron.hs
@ -155,7 +155,7 @@ nextCronMatch :: TZ -- ^ Timezone of the `Cron`-Entry
|
|||||||
-> UTCTime -- ^ Current time, used only for `CronCalendar`
|
-> UTCTime -- ^ Current time, used only for `CronCalendar`
|
||||||
-> Cron
|
-> Cron
|
||||||
-> CronNextMatch UTCTime
|
-> CronNextMatch UTCTime
|
||||||
nextCronMatch tz mPrev prec now c@Cron{..} = case notAfter of
|
nextCronMatch tz mPrev prec now c@Cron{..} = onlyOnceWithinPrec $ case notAfter of
|
||||||
MatchAsap -> MatchNone
|
MatchAsap -> MatchNone
|
||||||
MatchAt ts
|
MatchAt ts
|
||||||
| MatchAt ts' <- nextMatch
|
| MatchAt ts' <- nextMatch
|
||||||
@ -165,6 +165,16 @@ nextCronMatch tz mPrev prec now c@Cron{..} = case notAfter of
|
|||||||
| otherwise -> MatchNone
|
| otherwise -> MatchNone
|
||||||
MatchNone -> nextMatch
|
MatchNone -> nextMatch
|
||||||
where
|
where
|
||||||
|
onlyOnceWithinPrec sched = case mPrev of
|
||||||
|
Nothing -> sched
|
||||||
|
Just prevT -> case sched of
|
||||||
|
MatchAsap
|
||||||
|
| now >= addUTCTime prec prevT -> MatchAsap
|
||||||
|
| otherwise -> MatchAt $ addUTCTime prec prevT
|
||||||
|
MatchAt ts -> let ts' = max ts $ addUTCTime prec prevT
|
||||||
|
in if | ts' <= addUTCTime prec now -> MatchAsap
|
||||||
|
| otherwise -> MatchAt ts'
|
||||||
|
MatchNone -> MatchNone
|
||||||
notAfter
|
notAfter
|
||||||
| Right c' <- cronNotAfter
|
| Right c' <- cronNotAfter
|
||||||
, Just ref <- notAfterRef
|
, Just ref <- notAfterRef
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user