On Thu, Jul 09, 2015 at 04:11:33PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
In this way, we can later report which jobs we executed, as, e.g.,
the maintenance daemon will have to do.
Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/Jobs.hs | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/Ganeti/Jobs.hs b/src/Ganeti/Jobs.hs
index 01c2ac8..bab15d5 100644
--- a/src/Ganeti/Jobs.hs
+++ b/src/Ganeti/Jobs.hs
@@ -38,6 +38,7 @@ module Ganeti.Jobs
, execWithCancel
, execJobsWait
, execJobsWaitOk
+ , execJobsWaitOkJid
, waitForJobs
) where
@@ -164,9 +165,10 @@ waitForJobs jids client = waitForJobs' 500000 15000000
else
return . Ok $ zip jids sts'
--- | Execute jobs and return @Ok@ only if all of them succeeded.
-execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ())
-execJobsWaitOk opcodes client = do
+-- | Execute jobs and return @Ok@ only if all of them succeeded; in
+-- this case, also return the list of Job IDs.
+execJobsWaitOkJid :: [[MetaOpCode]] -> L.Client -> IO (Result [JobId])
+execJobsWaitOkJid opcodes client = do
let nullog = const (return () :: IO ())
failed = filter ((/=) JOB_STATUS_SUCCESS . snd)
fmtfail (i, s) = show (fromJobId i) ++ "=>" ++ jobStatusToRaw s
@@ -174,7 +176,12 @@ execJobsWaitOk opcodes client = do
case sts of
Bad e -> return $ Bad e
Ok sts' -> return (if null $ failed sts' then
- Ok ()
+ Ok $ map fst sts'
else
Bad ("The following jobs failed: " ++
(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 (fmap $ const ()) . execJobsWaitOkJid opcodes
Just nitpicking, `fmap (const ())` can be replaced by `void` from
Control.Monad; no need to resend, if you decide to use it.
In either case LGTM, thanks
--
2.4.3.573.g4eafbef