LGTM, thanks.
On Wed, Feb 5, 2014 at 2:49 PM, Klaus Aehlig <[email protected]> wrote: > ...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: Klaus Aehlig <[email protected]> > --- > src/Ganeti/JQScheduler.hs | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) > > diff --git a/src/Ganeti/JQScheduler.hs b/src/Ganeti/JQScheduler.hs > index 7767526..cdfe982 100644 > --- a/src/Ganeti/JQScheduler.hs > +++ b/src/Ganeti/JQScheduler.hs > @@ -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 > --- before being handed over to execution, False if it already was started > +-- 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. > -rmJob :: JobId -> Queue -> (Queue, Result Bool) > +rmJob :: JobId -> Queue -> (Queue, Result (Maybe QueuedJob)) > rmJob jid q = > let isJid = (jid ==) . qjId . jJob > (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") > - else (q {qEnqueued = queued'}, Ok True) > + 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' > -- > 1.9.0.rc1.175.g0b1dcb5 > >
