{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Network.Wait.Redis (
waitRedis,
waitRedisVerbose,
waitRedisVerboseFormat,
waitRedisWith
) where
import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Retry
import Database.Redis
import Network.Wait
waitRedis
:: (MonadIO m, MonadMask m)
=> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedis :: RetryPolicyM m -> ConnectInfo -> m Connection
waitRedis = [RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> ConnectInfo -> m Connection
forall (m :: * -> *).
(MonadIO m, MonadMask m) =>
[RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisWith []
waitRedisVerbose
:: (MonadIO m, MonadMask m)
=> (String -> m ()) -> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisVerbose :: (String -> m ()) -> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisVerbose String -> m ()
out =
forall e (m :: * -> *).
(MonadIO m, MonadMask m, Exception e) =>
(Bool -> e -> RetryStatus -> m ())
-> RetryPolicyM m -> ConnectInfo -> m Connection
forall (m :: * -> *).
(MonadIO m, MonadMask m, Exception SomeException) =>
(Bool -> SomeException -> RetryStatus -> m ())
-> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisVerboseFormat @SomeException ((Bool -> SomeException -> RetryStatus -> m ())
-> RetryPolicyM m -> ConnectInfo -> m Connection)
-> (Bool -> SomeException -> RetryStatus -> m ())
-> RetryPolicyM m
-> ConnectInfo
-> m Connection
forall a b. (a -> b) -> a -> b
$
\Bool
b SomeException
ex RetryStatus
st -> String -> m ()
out (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ Bool -> SomeException -> RetryStatus -> String
forall e. Exception e => Bool -> e -> RetryStatus -> String
defaultLogMsg Bool
b SomeException
ex RetryStatus
st
waitRedisVerboseFormat
:: forall e m . (MonadIO m, MonadMask m, Exception e)
=> (Bool -> e -> RetryStatus -> m ())
-> RetryPolicyM m
-> ConnectInfo
-> m Connection
waitRedisVerboseFormat :: (Bool -> e -> RetryStatus -> m ())
-> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisVerboseFormat Bool -> e -> RetryStatus -> m ()
out = [RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> ConnectInfo -> m Connection
forall (m :: * -> *).
(MonadIO m, MonadMask m) =>
[RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisWith [RetryStatus -> Handler m Bool
h]
where h :: RetryStatus -> Handler m Bool
h = (e -> m Bool)
-> (Bool -> e -> RetryStatus -> m ())
-> RetryStatus
-> Handler m Bool
forall (m :: * -> *) e.
(Monad m, Exception e) =>
(e -> m Bool)
-> (Bool -> e -> RetryStatus -> m ())
-> RetryStatus
-> Handler m Bool
logRetries (m Bool -> e -> m Bool
forall a b. a -> b -> a
const (m Bool -> e -> m Bool) -> m Bool -> e -> m Bool
forall a b. (a -> b) -> a -> b
$ Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True) Bool -> e -> RetryStatus -> m ()
out
waitRedisWith
:: (MonadIO m, MonadMask m)
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> ConnectInfo
-> m Connection
waitRedisWith :: [RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> ConnectInfo -> m Connection
waitRedisWith [RetryStatus -> Handler m Bool]
hs RetryPolicyM m
policy = [RetryStatus -> Handler m Bool]
-> RetryPolicyM m -> m Connection -> m Connection
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
[RetryStatus -> Handler m Bool] -> RetryPolicyM m -> m a -> m a
recoveringWith [RetryStatus -> Handler m Bool]
hs RetryPolicyM m
policy (m Connection -> m Connection)
-> (ConnectInfo -> m Connection) -> ConnectInfo -> m Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Connection -> m Connection
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Connection -> m Connection)
-> (ConnectInfo -> IO Connection) -> ConnectInfo -> m Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectInfo -> IO Connection
checkedConnect