diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-08 11:48:28 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-08 11:48:28 -0400 |
commit | 7ea377dadf61a4acf8ecdfec39954e7b4344c65f (patch) | |
tree | f37feed88774b13c8d503484d5e1417441d84ffb /Logs | |
parent | 6abf023cb98a5d3b2f9fb251055270e576570983 (diff) |
half way complete cronner thread to run scheduled activities
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/Schedule.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Logs/Schedule.hs b/Logs/Schedule.hs index 8f4c8b93a..7fc210c14 100644 --- a/Logs/Schedule.hs +++ b/Logs/Schedule.hs @@ -10,10 +10,14 @@ module Logs.Schedule ( scheduleSet, scheduleGet, scheduleMap, + getLastRunTimes, + setLastRunTime, ) where import qualified Data.Map as M +import qualified Data.Set as S import Data.Time.Clock.POSIX +import Data.Time.LocalTime import Common.Annex import Types.ScheduledActivity @@ -37,7 +41,19 @@ scheduleMap = simpleMap where parser _uuid = Just . mapMaybe toScheduledActivity . split "; " -scheduleGet :: UUID -> Annex [ScheduledActivity] +scheduleGet :: UUID -> Annex (S.Set ScheduledActivity) scheduleGet u = do m <- scheduleMap - return $ fromMaybe [] $ M.lookup u m + return $ maybe S.empty S.fromList (M.lookup u m) + +getLastRunTimes :: Annex (M.Map ScheduledActivity LocalTime) +getLastRunTimes = do + f <- fromRepo gitAnnexScheduleState + liftIO $ fromMaybe M.empty + <$> catchDefaultIO Nothing (readish <$> readFile f) + +setLastRunTime :: ScheduledActivity -> LocalTime -> Annex () +setLastRunTime activity lastrun = do + f <- fromRepo gitAnnexScheduleState + liftIO . writeFile f . show . M.insert activity lastrun + =<< getLastRunTimes |