From 3b23f238756b52e29131743065c22ad2d5c6cf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dato=20Sim=C3=B3?= <dato@google.com> Date: Thu, 15 Nov 2012 12:45:48 +0000 Subject: [PATCH] Hbal.hs: rename functions that deal with early termination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Hbal.hs, it's easy to get lost in the flow of exec* functions because their names are similar and don't convey their different purposes (e.g. runJobSet, execJobSet, execWrapper). This patch renames 'runJobSet' to 'execWithCancel', and 'execWrapper' to 'execCancelWrapper', since these two functions deal, in particular, with early termination when the user presses ^C. Signed-off-by: Dato SimΓ³ <dato@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htools/Ganeti/HTools/Program/Hbal.hs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/htools/Ganeti/HTools/Program/Hbal.hs b/htools/Ganeti/HTools/Program/Hbal.hs index e54b4d1cc..c7345a87d 100644 --- a/htools/Ganeti/HTools/Program/Hbal.hs +++ b/htools/Ganeti/HTools/Program/Hbal.hs @@ -192,11 +192,11 @@ waitForJobs client jids = do checkJobsStatus :: [JobStatus] -> Bool checkJobsStatus = all (== JOB_STATUS_SUCCESS) --- | Wrapper over execJobSet checking for early termination. -execWrapper :: String -> Node.List - -> Instance.List -> IORef Int -> [JobSet] -> IO Bool -execWrapper _ _ _ _ [] = return True -execWrapper master nl il cref alljss = do +-- | Wrapper over execJobSet checking for early termination via an IORef. +execCancelWrapper :: String -> Node.List + -> Instance.List -> IORef Int -> [JobSet] -> IO Bool +execCancelWrapper _ _ _ _ [] = return True +execCancelWrapper master nl il cref alljss = do cancel <- readIORef cref if cancel > 0 then do @@ -231,7 +231,7 @@ execJobSet master nl il cref (js:jss) = do hPutStrLn stderr x return False Ok x -> if checkJobsStatus x - then execWrapper master nl il cref jss + then execCancelWrapper master nl il cref jss else do hPutStrLn stderr $ "Not all jobs completed successfully: " ++ show x @@ -251,7 +251,7 @@ maybeExecJobs opts ord_plc fin_nl il cmd_jobs = Nothing -> do hPutStrLn stderr "Execution of commands possible only on LUXI" return False - Just master -> runJobSet master fin_nl il cmd_jobs) + Just master -> execWithCancel master fin_nl il cmd_jobs) else return True -- | Signal handler for graceful termination. @@ -269,13 +269,14 @@ handleSigTerm cref = do putStrLn "Double cancel request, exiting now..." exitImmediately $ ExitFailure 2 --- | Runs a job set with handling of signals. -runJobSet :: String -> Node.List -> Instance.List -> [JobSet] -> IO Bool -runJobSet master fin_nl il cmd_jobs = do +-- | Prepares to run a set of jobsets with handling of signals and early +-- termination. +execWithCancel :: String -> Node.List -> Instance.List -> [JobSet] -> IO Bool +execWithCancel master fin_nl il cmd_jobs = do cref <- newIORef 0 mapM_ (\(hnd, sig) -> installHandler sig (Catch (hnd cref)) Nothing) [(handleSigTerm, softwareTermination), (handleSigInt, keyboardSignal)] - execWrapper master fin_nl il cref cmd_jobs + execCancelWrapper master fin_nl il cref cmd_jobs -- | Select the target node group. selectGroup :: Options -> Group.List -> Node.List -> Instance.List -- GitLab