diff --git a/src/Jobs.hs b/src/Jobs.hs index 5969c4f08..c61b92bd5 100644 --- a/src/Jobs.hs +++ b/src/Jobs.hs @@ -334,10 +334,19 @@ setSerializable act = setSerializable' (0 :: Integer) (\e -> $logWarnS "SQL" (tshow e) *> threadDelay (1e3 * 2 ^ logBackoff) *> setSerializable' (succ logBackoff)) act' +pruneLastExecs :: Crontab JobCtl -> DB () +pruneLastExecs crontab = runConduit $ selectSource [] [] .| C.mapM_ ensureCrontab + where + ensureCrontab (Entity leId CronLastExec{..}) + | Just job <- Aeson.parseMaybe parseJSON cronLastExecJob + , HashMap.member (JobCtlQueue job) crontab + = return () + | otherwise = delete leId + determineCrontab :: DB (Crontab JobCtl) -- ^ Extract all future jobs from the database (sheet deadlines, ...) -determineCrontab = execWriterT $ do +determineCrontab = (\ct -> ct <$ pruneLastExecs ct) <=< execWriterT $ do AppSettings{..} <- getsYesod appSettings case appJobFlushInterval of @@ -377,7 +386,6 @@ determineCrontab = execWriterT $ do { cronInitial = CronTimestamp . utcToLocalTimeTZ appTZ . max sheetActiveFrom $ addUTCTime (-nominalDay) sheetActiveTo , cronRepeat = Nothing } - runConduit $ transPipe lift (selectSource [] []) .| C.mapM_ sheetJobs