From 164947ccbc2804dda59748206c4609c4d30ef417 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dato=20Sim=C3=B3?= <dato@google.com>
Date: Wed, 12 Dec 2012 15:32:46 +0000
Subject: [PATCH] Jobs.hs: make L.Client the last argument for all functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Having the Luxi client be the last argument of the functions allows for
easier use with `Exception.bracket L.getClient L.closeClient ...`.

Signed-off-by: Dato SimΓ³ <dato@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 htools/Ganeti/HTools/Program/Hbal.hs |  4 ++--
 htools/Ganeti/Jobs.hs                | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/htools/Ganeti/HTools/Program/Hbal.hs b/htools/Ganeti/HTools/Program/Hbal.hs
index e6a63322d..956d31827 100644
--- a/htools/Ganeti/HTools/Program/Hbal.hs
+++ b/htools/Ganeti/HTools/Program/Hbal.hs
@@ -196,8 +196,8 @@ execJobSet master nl il cref (js:jss) = do
       descr = map (\(_, idx, _, _) -> Container.nameOf il idx) js
       logfn = putStrLn . ("Got job IDs" ++) . commaJoin . map (show . fromJobId)
   putStrLn $ "Executing jobset for instances " ++ commaJoin descr
-  jrs <- bracket (L.getClient master) L.closeClient
-         (\client -> Jobs.execJobsWait client jobs logfn)
+  jrs <- bracket (L.getClient master) L.closeClient $
+         Jobs.execJobsWait jobs logfn
   case jrs of
     Bad x -> return $ Bad x
     Ok x -> if null failures
diff --git a/htools/Ganeti/Jobs.hs b/htools/Ganeti/Jobs.hs
index e35f928e8..7990a77bc 100644
--- a/htools/Ganeti/Jobs.hs
+++ b/htools/Ganeti/Jobs.hs
@@ -38,22 +38,22 @@ import Ganeti.Types
 
 -- | Executes a set of jobs and waits for their completion, returning their
 -- status.
-execJobsWait :: L.Client              -- ^ The Luxi client
-             -> [[MetaOpCode]]        -- ^ The list of jobs
+execJobsWait :: [[MetaOpCode]]        -- ^ The list of jobs
              -> ([L.JobId] -> IO ())  -- ^ Post-submission callback
+             -> L.Client              -- ^ The Luxi client
              -> IO (Result [(L.JobId, JobStatus)])
-execJobsWait client opcodes callback = do
+execJobsWait opcodes callback client = do
   jids <- L.submitManyJobs client opcodes
   case jids of
     Bad e -> return . Bad $ "Job submission error: " ++ formatError e
     Ok jids' -> do
       callback jids'
-      waitForJobs client jids'
+      waitForJobs jids' client
 
 -- | Polls a set of jobs at a fixed interval until all are finished
 -- one way or another.
-waitForJobs :: L.Client -> [L.JobId] -> IO (Result [(L.JobId, JobStatus)])
-waitForJobs client jids = do
+waitForJobs :: [L.JobId] -> L.Client -> IO (Result [(L.JobId, JobStatus)])
+waitForJobs jids client = do
   sts <- L.queryJobsStatus client jids
   case sts of
     Bad e -> return . Bad $ "Checking job status: " ++ formatError e
@@ -61,5 +61,5 @@ waitForJobs client jids = do
             then do
               -- TODO: replace hardcoded value with a better thing
               threadDelay (1000000 * 15)
-              waitForJobs client jids
+              waitForJobs jids client
             else return . Ok $ zip jids sts'
-- 
GitLab