{-# LANGUAGE RankNTypes #-}
module UnliftIO.Retry
(
RetryPolicyM (..)
, RetryPolicy
, retryPolicy
, retryPolicyDefault
, natTransformRetryPolicy
, RetryAction (..)
, toRetryAction
, RetryStatus (..)
, defaultRetryStatus
, applyPolicy
, applyAndDelay
, rsIterNumberL
, rsCumulativeDelayL
, rsPreviousDelayL
, retrying
, retryingDynamic
, recovering
, recoveringDynamic
, stepping
, recoverAll
, skipAsyncExceptions
, logRetries
, defaultLogMsg
, retryOnError
, resumeRetrying
, resumeRetryingDynamic
, resumeRecovering
, resumeRecoveringDynamic
, resumeRecoverAll
, constantDelay
, exponentialBackoff
, fullJitterBackoff
, fibonacciBackoff
, limitRetries
, limitRetriesByDelay
, limitRetriesByCumulativeDelay
, capDelay
, simulatePolicy
, simulatePolicyPP
) where
import Control.Retry hiding
( recoverAll
, recovering
, recoveringDynamic
, resumeRecovering
, resumeRecoveringDynamic
, resumeRecoverAll
, stepping
)
import qualified Control.Retry as Retry
import Control.Monad.Catch (Handler(..))
import Control.Monad.IO.Unlift (MonadUnliftIO, withRunInIO)
import Prelude
recovering
:: MonadUnliftIO m
=> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m a)
-> m a
recovering :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryPolicyM m
-> [RetryStatus -> Handler m Bool] -> (RetryStatus -> m a) -> m a
recovering = forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m a)
-> m a
resumeRecovering RetryStatus
defaultRetryStatus
resumeRecovering
:: MonadUnliftIO m
=> RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m a)
-> m a
resumeRecovering :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m a)
-> m a
resumeRecovering RetryStatus
retryStatus RetryPolicyM m
policy [RetryStatus -> Handler m Bool]
hs RetryStatus -> m a
f = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
runInIO ->
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m a)
-> m a
Retry.resumeRecovering
RetryStatus
retryStatus
(forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy forall a. m a -> IO a
runInIO RetryPolicyM m
policy)
(forall a b. (a -> b) -> [a] -> [b]
map (forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (n :: * -> *) a.
(forall b. m b -> n b) -> Handler m a -> Handler n a
transHandler forall a. m a -> IO a
runInIO) [RetryStatus -> Handler m Bool]
hs)
(forall a. m a -> IO a
runInIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m a
f)
recoveringDynamic
:: MonadUnliftIO m
=> RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
recoveringDynamic :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
recoveringDynamic = forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
resumeRecoveringDynamic RetryStatus
defaultRetryStatus
resumeRecoveringDynamic
:: MonadUnliftIO m
=> RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
resumeRecoveringDynamic :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
resumeRecoveringDynamic RetryStatus
retryStatus RetryPolicyM m
policy [RetryStatus -> Handler m RetryAction]
hs RetryStatus -> m a
f = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
runInIO ->
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
RetryStatus
-> RetryPolicyM m
-> [RetryStatus -> Handler m RetryAction]
-> (RetryStatus -> m a)
-> m a
Retry.resumeRecoveringDynamic
RetryStatus
retryStatus
(forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy forall a. m a -> IO a
runInIO RetryPolicyM m
policy)
(forall a b. (a -> b) -> [a] -> [b]
map (forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (n :: * -> *) a.
(forall b. m b -> n b) -> Handler m a -> Handler n a
transHandler forall a. m a -> IO a
runInIO) [RetryStatus -> Handler m RetryAction]
hs)
(forall a. m a -> IO a
runInIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m a
f)
recoverAll
:: MonadUnliftIO m
=> RetryPolicyM m
-> (RetryStatus -> m a)
-> m a
recoverAll :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryPolicyM m -> (RetryStatus -> m a) -> m a
recoverAll = forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus -> RetryPolicyM m -> (RetryStatus -> m a) -> m a
resumeRecoverAll RetryStatus
defaultRetryStatus
resumeRecoverAll
:: MonadUnliftIO m
=> RetryStatus
-> RetryPolicyM m
-> (RetryStatus -> m a)
-> m a
resumeRecoverAll :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryStatus -> RetryPolicyM m -> (RetryStatus -> m a) -> m a
resumeRecoverAll RetryStatus
retryStatus RetryPolicyM m
policy RetryStatus -> m a
f = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
runInIO ->
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
RetryStatus -> RetryPolicyM m -> (RetryStatus -> m a) -> m a
Retry.resumeRecoverAll
RetryStatus
retryStatus
(forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy forall a. m a -> IO a
runInIO RetryPolicyM m
policy)
(forall a. m a -> IO a
runInIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m a
f)
stepping
:: MonadUnliftIO m
=> RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m ())
-> (RetryStatus -> m a)
-> RetryStatus
-> m (Maybe a)
stepping :: forall (m :: * -> *) a.
MonadUnliftIO m =>
RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m ())
-> (RetryStatus -> m a)
-> RetryStatus
-> m (Maybe a)
stepping RetryPolicyM m
policy [RetryStatus -> Handler m Bool]
hs RetryStatus -> m ()
schedule RetryStatus -> m a
f RetryStatus
s = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
runInIO ->
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
RetryPolicyM m
-> [RetryStatus -> Handler m Bool]
-> (RetryStatus -> m ())
-> (RetryStatus -> m a)
-> RetryStatus
-> m (Maybe a)
Retry.stepping
(forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy forall a. m a -> IO a
runInIO RetryPolicyM m
policy)
(forall a b. (a -> b) -> [a] -> [b]
map (forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (n :: * -> *) a.
(forall b. m b -> n b) -> Handler m a -> Handler n a
transHandler forall a. m a -> IO a
runInIO) [RetryStatus -> Handler m Bool]
hs)
(forall a. m a -> IO a
runInIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m ()
schedule)
(forall a. m a -> IO a
runInIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m a
f)
RetryStatus
s
transRetryPolicy :: (forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy :: forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> RetryPolicyM m -> RetryPolicyM n
transRetryPolicy forall a. m a -> n a
f (RetryPolicyM RetryStatus -> m (Maybe Int)
p) = forall (m :: * -> *).
(RetryStatus -> m (Maybe Int)) -> RetryPolicyM m
RetryPolicyM forall a b. (a -> b) -> a -> b
$ forall a. m a -> n a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. RetryStatus -> m (Maybe Int)
p
transHandler :: (forall b. m b -> n b) -> Handler m a -> Handler n a
transHandler :: forall (m :: * -> *) (n :: * -> *) a.
(forall b. m b -> n b) -> Handler m a -> Handler n a
transHandler forall b. m b -> n b
f (Handler e -> m a
h) = forall (m :: * -> *) a e. Exception e => (e -> m a) -> Handler m a
Handler forall a b. (a -> b) -> a -> b
$ forall b. m b -> n b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
h