LGTM, thanks.
On Thu, Apr 10, 2014 at 11:57 AM, Klaus Aehlig <[email protected]> wrote: > Jobs may depend on other jobs in the sense that they may only be started > once a given job is finalized. For a job process, however, it is hard to > determine if the status of a different job without a significant overhead. > Therefore, only hand over to execution those jobs where all jobs they > depend > on have been finalized. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > src/Ganeti/JQScheduler.hs | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/src/Ganeti/JQScheduler.hs b/src/Ganeti/JQScheduler.hs > index 50bc4a2..ced0db6 100644 > --- a/src/Ganeti/JQScheduler.hs > +++ b/src/Ganeti/JQScheduler.hs > @@ -32,6 +32,7 @@ module Ganeti.JQScheduler > , setJobPriority > ) where > > +import Control.Applicative (liftA2) > import Control.Arrow > import Control.Concurrent > import Control.Exception > @@ -202,12 +203,21 @@ attachWatcher state jWS = when (isNothing $ jINotify > jWS) $ do > _ <- addWatch inotify [Modify, Delete] fpath $ jobWatcher state jWS' > modifyJobs state . onRunningJobs $ updateJobStatus jWS' > > +-- | For a queued job, determine whether it is eligible to run, i.e., > +-- if no jobs it depends on are either enqueued or running. > +jobEligible :: Queue -> JobWithStat -> Bool > +jobEligible queue jWS = > + let jdeps = getJobDependencies $ jJob jWS > + blocks = flip elem jdeps . qjId . jJob > + in not . any blocks . liftA2 (++) qRunning qEnqueued $ queue > + > -- | Decide on which jobs to schedule next for execution. This is the > -- pure function doing the scheduling. > selectJobsToRun :: Int -> Queue -> (Queue, [JobWithStat]) > selectJobsToRun count queue = > let n = count - length (qRunning queue) > - (chosen, remain) = splitAt n (qEnqueued queue) > + chosen = take n . filter (jobEligible queue) $ qEnqueued queue > + remain = deleteFirstsBy ((==) `on` (qjId . jJob)) (qEnqueued queue) > chosen > in (queue {qEnqueued=remain, qRunning=qRunning queue ++ chosen}, chosen) > > -- | Requeue jobs that were previously selected for execution > -- > 1.9.1.423.g4596e3a > >
