LGTM, thanks

On Mon, Dec 23, 2013 at 6:23 PM, Klaus Aehlig <[email protected]> wrote:

> Add a function that can serve as an event handler for inotify
> updating a job in the job queue if the corresponding job file
> changes. Also attach it to all jobs selected to be run.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/JQScheduler.hs | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/src/Ganeti/JQScheduler.hs b/src/Ganeti/JQScheduler.hs
> index e044833..1924ad0 100644
> --- a/src/Ganeti/JQScheduler.hs
> +++ b/src/Ganeti/JQScheduler.hs
> @@ -35,6 +35,7 @@ import Control.Concurrent
>  import Control.Exception
>  import Control.Monad
>  import Data.List
> +import Data.Maybe
>  import Data.IORef
>  import System.INotify
>
> @@ -158,6 +159,34 @@ cleanupFinishedJobs qstate = do
>      . logInfo $ "Finished jobs: " ++ jlist
>    mapM_ (maybe (return ()) killINotify . jINotify) finished
>
> +-- | Watcher task for a job, to update it on file changes. It also
> +-- reinstantiates itself upon receiving an Ignored event.
> +jobWatcher :: JQStatus -> JobWithStat -> Event -> IO ()
> +jobWatcher state jWS e = do
> +  let jid = qjId $ jJob jWS
> +      jids = show $ fromJobId jid
> +  logInfo $ "Scheduler notified of change of job " ++ jids
> +  logDebug $ "Scheulder notify event for " ++ jids ++ ": " ++ show e
> +  let inotify = jINotify jWS
> +  when (e == Ignored  && isJust inotify) $ do
> +    qdir <- queueDir
> +    let fpath = liveJobFile qdir jid
> +    _ <- addWatch (fromJust inotify) [Modify, Delete] fpath
> +           (jobWatcher state jWS)
> +    return ()
> +  updateJob state jWS
> +
> +-- | Attach the job watcher to a running job.
> +attachWatcher :: JQStatus -> JobWithStat -> IO ()
> +attachWatcher state jWS = when (isNothing $ jINotify jWS) $ do
> +  inotify <- initINotify
> +  qdir <- queueDir
> +  let fpath = liveJobFile qdir . qjId $ jJob jWS
> +      jWS' = jWS { jINotify=Just inotify }
> +  logDebug $ "Attaching queue watcher for " ++ fpath
> +  _ <- addWatch inotify [Modify, Delete] fpath $ jobWatcher state jWS'
> +  modifyJobs state . onRunningJobs $ updateJobStatus jWS'
> +
>  -- | Decide on which jobs to schedule next for execution. This is the
>  -- pure function doing the scheduling.
>  selectJobsToRun :: Queue -> (Queue, [JobWithStat])
> @@ -186,6 +215,7 @@ scheduleSomeJobs qstate = do
>    let jobs = map jJob chosen
>    unless (null chosen) . logInfo . (++) "Starting jobs: " . commaJoin
>      $ map (show . fromJobId . qjId) jobs
> +  mapM_ (attachWatcher qstate) chosen
>    result <- try $ JQ.startJobs jobs
>    either (requeueJobs qstate chosen) return result
>
> --
> 1.8.5.1
>
>


-- 
-- 
Helga Velroyen | Software Engineer | [email protected] |

Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to