Commit 164947cc authored by Dato Simó's avatar Dato Simó
Browse files

Jobs.hs: make L.Client the last argument for all functions



Having the Luxi client be the last argument of the functions allows for
easier use with `Exception.bracket L.getClient L.closeClient ...`.
Signed-off-by: default avatarDato Simó <dato@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 5f2cdb2a
......@@ -196,8 +196,8 @@ execJobSet master nl il cref (js:jss) = do
descr = map (\(_, idx, _, _) -> Container.nameOf il idx) js
logfn = putStrLn . ("Got job IDs" ++) . commaJoin . map (show . fromJobId)
putStrLn $ "Executing jobset for instances " ++ commaJoin descr
jrs <- bracket (L.getClient master) L.closeClient
(\client -> Jobs.execJobsWait client jobs logfn)
jrs <- bracket (L.getClient master) L.closeClient $
Jobs.execJobsWait jobs logfn
case jrs of
Bad x -> return $ Bad x
Ok x -> if null failures
......
......@@ -38,22 +38,22 @@ import Ganeti.Types
-- | Executes a set of jobs and waits for their completion, returning their
-- status.
execJobsWait :: L.Client -- ^ The Luxi client
-> [[MetaOpCode]] -- ^ The list of jobs
execJobsWait :: [[MetaOpCode]] -- ^ The list of jobs
-> ([L.JobId] -> IO ()) -- ^ Post-submission callback
-> L.Client -- ^ The Luxi client
-> IO (Result [(L.JobId, JobStatus)])
execJobsWait client opcodes callback = do
execJobsWait opcodes callback client = do
jids <- L.submitManyJobs client opcodes
case jids of
Bad e -> return . Bad $ "Job submission error: " ++ formatError e
Ok jids' -> do
callback jids'
waitForJobs client jids'
waitForJobs jids' client
-- | Polls a set of jobs at a fixed interval until all are finished
-- one way or another.
waitForJobs :: L.Client -> [L.JobId] -> IO (Result [(L.JobId, JobStatus)])
waitForJobs client jids = do
waitForJobs :: [L.JobId] -> L.Client -> IO (Result [(L.JobId, JobStatus)])
waitForJobs jids client = do
sts <- L.queryJobsStatus client jids
case sts of
Bad e -> return . Bad $ "Checking job status: " ++ formatError e
......@@ -61,5 +61,5 @@ waitForJobs client jids = do
then do
-- TODO: replace hardcoded value with a better thing
threadDelay (1000000 * 15)
waitForJobs client jids
waitForJobs jids client
else return . Ok $ zip jids sts'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment