Effect.Aff.Retry
- Package
- purescript-aff-retry
- Repository
- Unisay/purescript-aff-retry
#RetryStatus Source
newtype RetryStatus
Datatype with stats about retries made thus far
Constructors
RetryStatus { cumulativeDelay :: Milliseconds, iterNumber :: Int, previousDelay :: Maybe Milliseconds }
Instances
#RetryPolicyM Source
newtype RetryPolicyM :: (Type -> Type) -> Type
newtype RetryPolicyM m
A 'RetryPolicyM' is a function that takes an 'RetryStatus' and possibly returns a delay in milliseconds. Iteration numbers start at zero and increase by one on each retry. A Nothing return value from the function implies we have reached the retry limit.
Please note that 'RetryPolicyM' is a 'Monoid'. You can collapse multiple strategies into one using 'mappend' or '<>'. The semantics of this combination are as follows:
If either policy returns 'Nothing', the combined policy returns 'Nothing'. This can be used to @inhibit@ after a number of retries, for example.
If both policies return a delay, the larger delay will be used. This is quite natural when combining multiple policies to achieve a certain effect.
Example:
One can easily define an exponential backoff policy with a limited number of retries:
Naturally, 'mempty' will retry immediately (delay 0) for an unlimited number of retries, forming the identity for the 'Monoid'.
Constructors
RetryPolicyM (RetryStatus -> m (Maybe Milliseconds))
Instances
(Monad m) => Semigroup (RetryPolicyM m)
(MonadAff m) => Monoid (RetryPolicyM m)
#RetryPolicy Source
type RetryPolicy = forall m. MonadAff m => RetryPolicyM m
#constantDelay Source
constantDelay :: forall d. Duration d => d -> RetryPolicy
Cconstant delay with unlimited retries
#exponentialBackoff Source
exponentialBackoff :: forall d. Duration d => d -> RetryPolicy
Grow delay exponentially each iteration. Each delay will increase by a factor of two.
#fibonacciBackoff Source
fibonacciBackoff :: forall d. Duration d => d -> RetryPolicy
#fullJitterBackoff Source
fullJitterBackoff :: forall m d. MonadAff m => Duration d => d -> RetryPolicyM m
FullJitter exponential backoff as explained in AWS Architecture Blog article. @http:\/\/www.awsarchitectureblog.com\/2015\/03\/backoff.html@ temp = min(cap, base * 2 ** attempt) sleep = temp / 2 + random_between(0, temp / 2)
#capDelay Source
capDelay :: forall d m. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m
Set a time-upperbound for any delays that may be directed by the
given policy. This function does not terminate the retrying. The policy
capDelay maxDelay (exponentialBackoff n)
will never stop retrying. It
will reach a state where it retries forever with a delay of maxDelay
between each one. To get termination you need to use one of the
'limitRetries' function variants.
#defaultRetryStatus Source
defaultRetryStatus :: RetryStatus
Initial, default retry status. Exported mostly to allow user code to test their handlers and retry policies. Use fields or lenses to update.
#applyAndDelay Source
applyAndDelay :: forall m. MonadAff m => RetryPolicyM m -> RetryStatus -> m (Maybe RetryStatus)
Apply policy and delay by its amount if it results in a retry. Returns updated status.
#applyPolicy Source
applyPolicy :: forall m. MonadAff m => RetryPolicyM m -> RetryStatus -> m (Maybe RetryStatus)
Apply policy on status to see what the decision would be. 'Nothing' implies no retry, 'Just' returns updated status.
#retryPolicy Source
retryPolicy :: (RetryStatus -> Maybe Milliseconds) -> RetryPolicy
Helper for making simplified policies that don't use the monadic context.
#limitRetries Source
limitRetries :: Int -> RetryPolicy
Retry immediately, but only up to @n@ times.
#limitRetriesByDelay Source
limitRetriesByDelay :: forall d m. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m
Add an upperbound to a policy such that once the given time-delay amount per try has been reached or exceeded, the policy will stop retrying and fail. If you need to stop retrying once cumulative delay reaches a time-delay amount, use 'limitRetriesByCumulativeDelay'
#limitRetriesByCumulativeDelay Source
limitRetriesByCumulativeDelay :: forall d m. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m
Add an upperbound to a policy such that once the cumulative delay over all retries has reached or exceeded the given limit, the policy will stop retrying and fail.
#retrying Source
retrying :: forall m b. MonadAff m => RetryPolicyM m -> (RetryStatus -> b -> m Boolean) -> (RetryStatus -> m b) -> m b
Retry combinator for actions that don't raise exceptions, but signal in their type the outcome has failed. Examples are the 'Maybe', 'Either' and 'EitherT' monads.
#recovering Source
recovering :: forall m a. MonadAff m => MonadError Error m => RetryPolicyM m -> Array (RetryStatus -> Error -> m Boolean) -> (RetryStatus -> m a) -> m a
Run an action and recover from a raised exception by potentially retrying the action a number of times.
- Modules
- Effect.
Aff. Retry