summaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-07 16:06:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-07 16:06:34 -0400
commita1119e81bafbf8cffdf2fb641d18f3e6185bb2e0 (patch)
tree641748f4975546703667bae4121179193a4b92e5 /Logs
parent8eeb2b5acef05965e24d730dbc9070f49066bf80 (diff)
add a log file for scheduled activities
Diffstat (limited to 'Logs')
-rw-r--r--Logs/Schedule.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Logs/Schedule.hs b/Logs/Schedule.hs
new file mode 100644
index 000000000..213aceeed
--- /dev/null
+++ b/Logs/Schedule.hs
@@ -0,0 +1,42 @@
+{- git-annex scheduled activities log
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Logs.Schedule (
+ scheduleLog,
+ scheduleSet,
+ scheduleGet,
+) where
+
+import qualified Data.Map as M
+import Data.Time.Clock.POSIX
+
+import Common.Annex
+import Types.ScheduledActivity
+import qualified Annex.Branch
+import Logs
+import Logs.UUIDBased
+
+scheduleSet :: UUID -> [ScheduledActivity] -> Annex ()
+scheduleSet uuid@(UUID _) activities = do
+ ts <- liftIO getPOSIXTime
+ Annex.Branch.change scheduleLog $
+ showLog id . changeLog ts uuid val . parseLog Just
+ where
+ val = intercalate "; " $ map fromScheduledActivity activities
+scheduleSet NoUUID _ = error "unknown UUID; cannot modify"
+
+scheduleMap :: Annex (M.Map UUID [ScheduledActivity])
+scheduleMap = simpleMap
+ . parseLogWithUUID parser
+ <$> Annex.Branch.get scheduleLog
+ where
+ parser _uuid = Just . mapMaybe toScheduledActivity . split "; "
+
+scheduleGet :: UUID -> Annex [ScheduledActivity]
+scheduleGet u = do
+ m <- scheduleMap
+ return $ fromMaybe [] $ M.lookup u m