Revision 155df343 src/Ganeti/JQScheduler.hs
b/src/Ganeti/JQScheduler.hs | ||
---|---|---|
300 | 300 |
scheduleSomeJobs state |
301 | 301 |
|
302 | 302 |
-- | Pure function for removing a queued job from the job queue by |
303 |
-- atomicModifyIORef. The answer is True if the job could be removed
|
|
304 |
-- before being handed over to execution, False if it already was started
|
|
303 |
-- atomicModifyIORef. The answer is Just the job if the job could be removed
|
|
304 |
-- before being handed over to execution, Nothing if it already was started
|
|
305 | 305 |
-- and a Bad result if the job is not found in the queue. |
306 |
rmJob :: JobId -> Queue -> (Queue, Result Bool)
|
|
306 |
rmJob :: JobId -> Queue -> (Queue, Result (Maybe QueuedJob))
|
|
307 | 307 |
rmJob jid q = |
308 | 308 |
let isJid = (jid ==) . qjId . jJob |
309 | 309 |
(found, queued') = partition isJid $ qEnqueued q |
310 |
in if null found |
|
311 |
then if any isJid $ qRunning q |
|
312 |
then (q, Ok False) |
|
313 |
else (q, Bad $ "Job " ++ show (fromJobId jid) |
|
314 |
++ " unknown to the queue") |
|
315 |
else (q {qEnqueued = queued'}, Ok True) |
|
310 |
isRunning = any isJid $ qRunning q |
|
311 |
sJid = (++) "Job " . show $ fromJobId jid |
|
312 |
in case (found, isRunning) of |
|
313 |
([job], _) -> (q {qEnqueued = queued'}, Ok . Just $ jJob job) |
|
314 |
(_:_, _) -> (q, Bad $ "Queue in inconsistent state." |
|
315 |
++ sJid ++ " queued multiple times") |
|
316 |
(_, True) -> (q, Ok Nothing) |
|
317 |
_ -> (q, Bad $ sJid ++ " not found in queue") |
|
316 | 318 |
|
317 | 319 |
-- | Try to remove a queued job from the job queue. Return True, if |
318 | 320 |
-- the job could be removed from the queue before being handed over |
... | ... | |
321 | 323 |
dequeueJob :: JQStatus -> JobId -> IO (Result Bool) |
322 | 324 |
dequeueJob state jid = do |
323 | 325 |
result <- atomicModifyIORef (jqJobs state) $ rmJob jid |
326 |
let result' = fmap isJust result |
|
324 | 327 |
logDebug $ "Result of dequeing job " ++ show (fromJobId jid) |
325 |
++ " is " ++ show result |
|
326 |
return result |
|
328 |
++ " is " ++ show result' |
|
329 |
return result' |
Also available in: Unified diff