Commit 155df343 authored by Klaus Aehlig's avatar Klaus Aehlig

Change return type of internal rmJob

...to also provide the job itself. In this way, the function can
also be used for tasks that require temporarily removing a job
from the queue.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent a6b33b72
......@@ -300,19 +300,21 @@ enqueueNewJobs state jobs = do
scheduleSomeJobs state
-- | Pure function for removing a queued job from the job queue by
-- atomicModifyIORef. The answer is True if the job could be removed
-- atomicModifyIORef. The answer is Just the job if the job could be removed
-- before being handed over to execution, Nothing if it already was started
-- and a Bad result if the job is not found in the queue.
-- and a Bad result if the job is not found in the queue.
rmJob :: JobId -> Queue -> (Queue, Result (Maybe QueuedJob))
rmJob jid q =
let isJid = (jid ==) . qjId . jJob
(found, queued') = partition isJid $ qEnqueued q
(found, queued') = partition isJid $ qEnqueued q
in if null found
then if any isJid $ qRunning q
then (q, Ok False)
else (q, Bad $ "Job " ++ show (fromJobId jid)
++ " unknown to the queue")
isRunning = any isJid $ qRunning q
sJid = (++) "Job " . show $ fromJobId jid
in case (found, isRunning) of
([job], _) -> (q {qEnqueued = queued'}, Ok . Just $ jJob job)
(_:_, _) -> (q, Bad $ "Queue in inconsistent state."
++ sJid ++ " queued multiple times")
(_, True) -> (q, Ok Nothing)
_ -> (q, Bad $ sJid ++ " not found in queue")
-- | Try to remove a queued job from the job queue. Return True, if
-- the job could be removed from the queue before being handed over
......@@ -321,6 +323,7 @@ rmJob jid q =
dequeueJob :: JQStatus -> JobId -> IO (Result Bool)
dequeueJob state jid = do
result <- atomicModifyIORef (jqJobs state) $ rmJob jid
let result' = fmap isJust result
logDebug $ "Result of dequeing job " ++ show (fromJobId jid)
++ " is " ++ show result
return result
++ " is " ++ show result'
return result'
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