Commit 6b57c489 authored by Klaus Aehlig's avatar Klaus Aehlig

Add a version of execJobsWaitOK that also returns the JobIds

In this way, we can later report which jobs we executed, as, e.g.,
the maintenance daemon will have to do.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 1a123f2d
...@@ -38,11 +38,13 @@ module Ganeti.Jobs ...@@ -38,11 +38,13 @@ module Ganeti.Jobs
, execWithCancel , execWithCancel
, execJobsWait , execJobsWait
, execJobsWaitOk , execJobsWaitOk
, execJobsWaitOkJid
, waitForJobs , waitForJobs
) where ) where
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import Control.Exception (bracket) import Control.Exception (bracket)
import Control.Monad (void)
import Data.List import Data.List
import Data.Tuple import Data.Tuple
import Data.IORef import Data.IORef
...@@ -164,9 +166,10 @@ waitForJobs jids client = waitForJobs' 500000 15000000 ...@@ -164,9 +166,10 @@ waitForJobs jids client = waitForJobs' 500000 15000000
else else
return . Ok $ zip jids sts' return . Ok $ zip jids sts'
-- | Execute jobs and return @Ok@ only if all of them succeeded. -- | Execute jobs and return @Ok@ only if all of them succeeded; in
execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ()) -- this case, also return the list of Job IDs.
execJobsWaitOk opcodes client = do execJobsWaitOkJid :: [[MetaOpCode]] -> L.Client -> IO (Result [JobId])
execJobsWaitOkJid opcodes client = do
let nullog = const (return () :: IO ()) let nullog = const (return () :: IO ())
failed = filter ((/=) JOB_STATUS_SUCCESS . snd) failed = filter ((/=) JOB_STATUS_SUCCESS . snd)
fmtfail (i, s) = show (fromJobId i) ++ "=>" ++ jobStatusToRaw s fmtfail (i, s) = show (fromJobId i) ++ "=>" ++ jobStatusToRaw s
...@@ -174,7 +177,12 @@ execJobsWaitOk opcodes client = do ...@@ -174,7 +177,12 @@ execJobsWaitOk opcodes client = do
case sts of case sts of
Bad e -> return $ Bad e Bad e -> return $ Bad e
Ok sts' -> return (if null $ failed sts' then Ok sts' -> return (if null $ failed sts' then
Ok () Ok $ map fst sts'
else else
Bad ("The following jobs failed: " ++ Bad ("The following jobs failed: " ++
(intercalate ", " . map fmtfail $ failed sts'))) (intercalate ", " . map fmtfail $ failed sts')))
-- | Execute jobs and return @Ok@ only if all of them succeeded.
execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ())
execJobsWaitOk opcodes =
fmap void . execJobsWaitOkJid opcodes
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