Revision 7d8b651e

b/src/Ganeti/Jobs.hs
26 26
module Ganeti.Jobs
27 27
  ( submitJobs
28 28
  , execJobsWait
29
  , execJobsWaitOk
29 30
  , waitForJobs
30 31
  ) where
31 32

  
32 33
import Control.Concurrent (threadDelay)
34
import Data.List
33 35

  
34 36
import Ganeti.BasicTypes
35 37
import Ganeti.Errors
......
73 75
              threadDelay (1000000 * 15)
74 76
              waitForJobs jids client
75 77
            else return . Ok $ zip jids sts'
78

  
79
-- | Execute jobs and return @Ok@ only if all of them succeeded.
80
execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ())
81
execJobsWaitOk opcodes client = do
82
  let nullog = const (return () :: IO ())
83
      failed = filter ((/=) JOB_STATUS_SUCCESS . snd)
84
      fmtfail (i, s) = show (fromJobId i) ++ "=>" ++ jobStatusToRaw s
85
  sts <- execJobsWait opcodes nullog client
86
  case sts of
87
    Bad e -> return $ Bad e
88
    Ok sts' -> return (if null $ failed sts' then
89
                         Ok ()
90
                       else
91
                         Bad ("The following jobs failed: " ++
92
                              (intercalate ", " . map fmtfail $ failed sts')))

Also available in: Unified diff