Revision b8e76da8 src/Ganeti/Jobs.hs

b/src/Ganeti/Jobs.hs
62 62
      callback jids'
63 63
      waitForJobs jids' client
64 64

  
65
-- | Polls a set of jobs at a fixed interval until all are finished
66
-- one way or another.
65
-- | Polls a set of jobs at an increasing interval until all are finished one
66
-- way or another.
67 67
waitForJobs :: [L.JobId] -> L.Client -> IO (Result [(L.JobId, JobStatus)])
68
waitForJobs jids client = do
69
  sts <- L.queryJobsStatus client jids
70
  case sts of
71
    Bad e -> return . Bad $ "Checking job status: " ++ formatError e
72
    Ok sts' -> if any (<= JOB_STATUS_RUNNING) sts'
73
            then do
74
              -- TODO: replace hardcoded value with a better thing
75
              threadDelay (1000000 * 15)
76
              waitForJobs jids client
77
            else return . Ok $ zip jids sts'
68
waitForJobs jids client = waitForJobs' 500000 15000000
69
  where
70
    waitForJobs' delay maxdelay = do
71
      -- TODO: this should use WaitForJobChange once it's available in Haskell
72
      -- land, instead of a fixed schedule of sleeping intervals.
73
      threadDelay $ min delay maxdelay
74
      sts <- L.queryJobsStatus client jids
75
      case sts of
76
        Bad e -> return . Bad $ "Checking job status: " ++ formatError e
77
        Ok sts' -> if any (<= JOB_STATUS_RUNNING) sts' then
78
                     waitForJobs' (delay * 2) maxdelay
79
                   else
80
                     return . Ok $ zip jids sts'
78 81

  
79 82
-- | Execute jobs and return @Ok@ only if all of them succeeded.
80 83
execJobsWaitOk :: [[MetaOpCode]] -> L.Client -> IO (Result ())

Also available in: Unified diff