A
RetryPolicyM is a function that takes an
RetryStatus
and possibly returns a delay in microseconds. 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:
> limitedBackoff = exponentialBackoff 50000 <> limitRetries 5
Naturally,
mempty will retry immediately (delay 0) for an
unlimited number of retries, forming the identity for the
Monoid.
The default retry policy
retryPolicyDefault implements a
constant 50ms delay, up to 5 times:
> retryPolicyDefault = constantDelay 50000 <> limitRetries 5
For anything more complex, just define your own
RetryPolicyM:
> myPolicy = retryPolicy $ \ rs -> if rsIterNumber rs > 10 then Just 1000 else Just 10000
Since 0.7.