2013-10-13 19:40:38 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-10-13 19:40:38 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-10-13 19:40:38 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Schedule where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Remote
|
|
|
|
import Logs.Schedule
|
|
|
|
import Types.ScheduledActivity
|
|
|
|
|
|
|
|
import qualified Data.Set as S
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2017-02-16 17:24:16 +00:00
|
|
|
cmd = noMessages $ command "schedule" SectionSetup "get or set scheduled jobs"
|
2015-07-08 19:08:02 +00:00
|
|
|
(paramPair paramRemote (paramOptional paramExpression))
|
|
|
|
(withParams seek)
|
2013-10-13 19:40:38 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . start)
|
2013-10-13 19:40:38 +00:00
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start = parse
|
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
parse (name:[]) = go name performGet
|
2013-10-13 19:40:38 +00:00
|
|
|
parse (name:expr:[]) = go name $ \uuid -> do
|
2017-02-16 17:24:16 +00:00
|
|
|
allowMessages
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' "schedule" (Just name)
|
2013-10-13 19:40:38 +00:00
|
|
|
performSet expr uuid
|
2016-11-16 01:29:54 +00:00
|
|
|
parse _ = giveup "Specify a repository."
|
2013-10-13 19:40:38 +00:00
|
|
|
|
|
|
|
go name a = do
|
|
|
|
u <- Remote.nameToUUID name
|
|
|
|
next $ a u
|
|
|
|
|
|
|
|
performGet :: UUID -> CommandPerform
|
|
|
|
performGet uuid = do
|
|
|
|
s <- scheduleGet uuid
|
|
|
|
liftIO $ putStrLn $ intercalate "; " $
|
|
|
|
map fromScheduledActivity $ S.toList s
|
|
|
|
next $ return True
|
|
|
|
|
|
|
|
performSet :: String -> UUID -> CommandPerform
|
|
|
|
performSet expr uuid = case parseScheduledActivities expr of
|
2016-11-16 01:29:54 +00:00
|
|
|
Left e -> giveup $ "Parse error: " ++ e
|
2013-10-13 19:40:38 +00:00
|
|
|
Right l -> do
|
|
|
|
scheduleSet uuid l
|
|
|
|
next $ return True
|