Commit 2bbd580d authored by Klaus Aehlig's avatar Klaus Aehlig

Add a utility function to try an RPC until it returns True

Due to the still existing configuration lock, modifications
to the configuration can temporarily be impossible. Therefore,
most configuration-modifying function return a Boolean indicating
whether the change was carried out. Add a utility function to
retry that change until it succeeds.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent c119f0bd
......@@ -38,14 +38,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module Ganeti.WConfd.Client where
import Control.Concurrent (threadDelay)
import Control.Exception.Lifted (bracket)
import Control.Monad (unless)
import Control.Monad.Base
import Control.Monad.Error (MonadError)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)
import Ganeti.THH.HsRPC
import Ganeti.BasicTypes (runResultT, GenericResult(..))
import Ganeti.Constants
import Ganeti.Errors (GanetiException)
import Ganeti.JSON (unMaybeForJSON)
......@@ -103,3 +103,14 @@ withLockedConfig :: ClientId
withLockedConfig c shared =
-- Unlock config even if something throws.
bracket (waitLockConfig c shared) (const $ unlockConfig c)
-- * Other functions
-- | Try an RPC until no errors occur and the result is true.
runModifyRpc :: RpcClientMonad Bool -> IO ()
runModifyRpc action = do
res <- runResultT $ runNewWConfdClient action
unless (res == Ok True) $ do
threadDelay 100000 -- sleep 0.1 seconds
runModifyRpc action
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment