aboutsummaryrefslogtreecommitdiff
path: root/src/server/Job.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Job.hs')
-rw-r--r--src/server/Job.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/server/Job.hs b/src/server/Job.hs
new file mode 100644
index 0000000..bf8f15b
--- /dev/null
+++ b/src/server/Job.hs
@@ -0,0 +1,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