On Thu, Jul 16, 2015 at 12:36:55PM +0200, Klaus Aehlig wrote:
>+-- | Get the list of jobs from the authoritative copy, and update the
>+-- in-memory copy as well.
>+getJobs :: IORef MemoryState -> ResultT String IO [JobId]
>+getJobs memstate = do
>+  wconfdClient <- liftIO $ getWConfdClient =<< Path.defaultWConfdSocket
>+  jobs <- withErrorT show $ runRpcClient maintenanceJobs wconfdClient

.. also I'd suggest to close the client here

>+  liftIO . atomicModifyIORef memstate $ \ s -> (s { msJobs = jobs }, ())
>+  return jobs

>+  luxiSocket <- liftIO Path.defaultQuerySocket
>+  lclient <- mkResultT . liftM (either (Bad . show) Ok)
>+             . tryIOError $ L.getLuxiClient luxiSocket
>+  void . mkResultT $ waitForJobs oldjobs lclient

.. and here

>+  liftIO $ clearJobs memstate

Interdiff

commit c7245e42c388576a9101600cf5df7f467383e7a3
Author: Klaus Aehlig <[email protected]>
Date:   Thu Jul 16 12:20:17 2015 +0200

   Interdiff [PATCH master 15/16] Make maintd wait for its jobs and also expose 
them

diff --git a/src/Ganeti/MaintD/MemoryState.hs b/src/Ganeti/MaintD/MemoryState.hs
index 592d0b5..7fd351a 100644
--- a/src/Ganeti/MaintD/MemoryState.hs
+++ b/src/Ganeti/MaintD/MemoryState.hs
@@ -52,11 +52,9 @@ import Control.Monad.IO.Class (liftIO)
import Data.IORef (IORef, atomicModifyIORef)

import Ganeti.BasicTypes (ResultT, withErrorT)
-import qualified Ganeti.Path as Path
-import Ganeti.THH.HsRPC (runRpcClient)
import Ganeti.Types (JobId)
import Ganeti.Utils (ordNub)
-import Ganeti.WConfd.Client ( getWConfdClient, maintenanceJobs, runModifyRpc
+import Ganeti.WConfd.Client ( runNewWConfdClient, maintenanceJobs, runModifyRpc
                            , clearMaintdJobs, appendMaintdJobs )

-- | In-memory copy of parts of the state of the maintenance
@@ -76,8 +74,7 @@ emptyMemoryState = MemoryState {
-- in-memory copy as well.
getJobs :: IORef MemoryState -> ResultT String IO [JobId]
getJobs memstate = do
-  wconfdClient <- liftIO $ getWConfdClient =<< Path.defaultWConfdSocket
-  jobs <- withErrorT show $ runRpcClient maintenanceJobs wconfdClient
+  jobs <- withErrorT show $ runNewWConfdClient maintenanceJobs
  liftIO . atomicModifyIORef memstate $ \ s -> (s { msJobs = jobs }, ())
  return jobs

diff --git a/src/Ganeti/MaintD/Server.hs b/src/Ganeti/MaintD/Server.hs
index e3ac20e..c68c7e3 100644
--- a/src/Ganeti/MaintD/Server.hs
+++ b/src/Ganeti/MaintD/Server.hs
@@ -43,6 +43,7 @@ module Ganeti.MaintD.Server

import Control.Applicative ((<|>))
import Control.Concurrent (forkIO)
+import Control.Exception.Lifted (bracket)
import Control.Monad (forever, void, unless, when, liftM)
import Control.Monad.IO.Class (liftIO)
import Data.IORef (IORef, newIORef, readIORef)
@@ -122,9 +123,10 @@ maintenance memstate = do
  logDebug $ "Jobs submitted in the last round: "
             ++ show (map fromJobId oldjobs)
  luxiSocket <- liftIO Path.defaultQuerySocket
-  lclient <- mkResultT . liftM (either (Bad . show) Ok)
-             . tryIOError $ L.getLuxiClient luxiSocket
-  void . mkResultT $ waitForJobs oldjobs lclient
+  bracket (mkResultT . liftM (either (Bad . show) Ok)
+            . tryIOError $ L.getLuxiClient luxiSocket)
+          (liftIO . L.closeClient)
+          $ void . mkResultT . waitForJobs oldjobs
  liftIO $ clearJobs memstate
  logDebug "New round of maintenance started"
  cData <- loadClusterData


--
Klaus Aehlig
Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores

LGTM, thanks

Reply via email to