diff options
author | Joris | 2017-06-05 18:02:13 +0200 |
---|---|---|
committer | Joris | 2017-06-05 18:02:13 +0200 |
commit | 0b191f5c48edffc9da3e38c284e9640fd82e7cb1 (patch) | |
tree | c729e53822e7c41c1a854d82d25636e58ee65c9f /src/server/Job/Daemon.hs | |
parent | 5c110716cfda6e616a795edd12f2012b132dca9f (diff) |
Replace persistent by sqlite-simple
Diffstat (limited to 'src/server/Job/Daemon.hs')
-rw-r--r-- | src/server/Job/Daemon.hs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/server/Job/Daemon.hs b/src/server/Job/Daemon.hs index 8259b18..0bc6f6e 100644 --- a/src/server/Job/Daemon.hs +++ b/src/server/Job/Daemon.hs @@ -2,21 +2,17 @@ module Job.Daemon ( runDaemons ) where -import Data.Time.Clock (UTCTime) - import Control.Concurrent (threadDelay, forkIO, ThreadId) import Control.Monad (forever) +import Data.Time.Clock (UTCTime) -import Model.Database - -import Job.Kind (Kind(..)) +import Conf (Conf) import Job.Frequency (Frequency(..), microSeconds) +import Job.Kind (Kind(..)) import Job.Model (getLastExecution, actualizeLastCheck, actualizeLastExecution) import Job.MonthlyPayment (monthlyPayment) import Job.WeeklyReport (weeklyReport) - -import Conf (Conf) - +import qualified Model.Query as Query import Utils.Time (belongToCurrentMonth, belongToCurrentWeek) runDaemons :: Conf -> IO () @@ -28,13 +24,13 @@ runDaemons conf = do runDaemon :: Kind -> Frequency -> (UTCTime -> IO Bool) -> (Maybe UTCTime -> IO UTCTime) -> IO ThreadId runDaemon kind frequency isLastExecutionTooOld runJob = forkIO . forever $ do - mbLastExecution <- runDb $ do + mbLastExecution <- Query.run $ do actualizeLastCheck kind getLastExecution kind hasToRun <- case mbLastExecution of Just lastExecution -> isLastExecutionTooOld lastExecution Nothing -> return True if hasToRun - then runJob mbLastExecution >>= (runDb . actualizeLastExecution kind) + then runJob mbLastExecution >>= (Query.run . actualizeLastExecution kind) else return () threadDelay . microSeconds $ frequency |