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`
|
||||
-> Cron
|
||||
-> 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
|
||||
MatchAt ts
|
||||
| MatchAt ts' <- nextMatch
|
||||
@ -165,6 +165,16 @@ nextCronMatch tz mPrev prec now c@Cron{..} = case notAfter of
|
||||
| otherwise -> MatchNone
|
||||
MatchNone -> nextMatch
|
||||
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
|
||||
| Right c' <- cronNotAfter
|
||||
, Just ref <- notAfterRef
|
||||
|
||||
Loading…
Reference in New Issue
Block a user