blob: bf8f15b19f3969811845e97d1d567af518b138a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
module Job
( jobListener
) where
import Data.Time.Clock
import Control.Concurrent (threadDelay)
import Model.Database
import Model.JobKind
import Model.Job
jobListener :: JobKind -> (UTCTime -> IO Bool) -> (() -> Persist ()) -> Int -> IO ()
jobListener kind lastExecutionTooOld runJob msDelay = do
mbLastExecution <- runDb $ do
actualizeLastCheck kind
getLastExecution kind
hasToRun <- case mbLastExecution of
Just lastExecution -> lastExecutionTooOld lastExecution
Nothing -> return True
if hasToRun
then runDb (runJob () >> actualizeLastExecution kind)
else return ()
threadDelay msDelay
jobListener kind lastExecutionTooOld runJob msDelay
|