!4      !"#$%&'()*+,-./0123(Ozgun Ataman <ozgun.ataman@soostone.com>BSD3 Ozgun Ataman provisionalNone "#%7FSX)retryTDatatype with stats about retries made thus far. The constructor is deliberately not exported to make additional fields easier to add in a backward-compatible manner. To read or modify fields in RetryStatus, use the accessors or lenses below. Note that if you don't want to use lenses, the exported field names can be used for updates: ]> retryStatus { rsIterNumber = newIterNumber } > retryStatus & rsIterNumberL .~ newIterNumberretry*Iteration number, where 0 is the first tryretry2Delay incurred so far from retries in microsecondsretry<Latest attempt's delay. Will always be Nothing on first run.retryHow to handle a failed action.retry$Don't retry (regardless of what the   says).retry Retry if the  1 says so, with the delay specified by the policy.retry Retry if the  C says so, but override the policy's delay (number of microseconds). retry Simplified   without any use of the monadic context in determining policy. Mostly maintains backwards compatitibility with type signatures pre-0.7. retryA   is a function that takes an  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   is a 47. You can collapse multiple strategies into one using 5 or 64. The semantics of this combination are as follows: If either policy returns 7, the combined policy returns 7. 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:VOne can easily define an exponential backoff policy with a limited number of retries: :> limitedBackoff = exponentialBackoff 50 <> limitRetries 5 Naturally, 8d will retry immediately (delay 0) for an unlimited number of retries, forming the identity for the 4.The default retry policy  1 implements a constant 50ms delay, up to 5 times: <> retryPolicyDefault = constantDelay 50000 <> limitRetries 50For anything more complex, just define your own  : X> myPolicy = retryPolicy $ \ rs -> if rsIterNumber n > 10 then Just 1000 else Just 10000 Since 0.7. retryDefault retry policyretryWApplies a natural transformation to a policy to run a RetryPolicy meant for the monad m in the monad n! provided a transformation from m to n< is available. A common case is if you have a pure policy, RetryPolicyM Identity" and want to use it to govern an IO computation you could write: } purePolicyInIO :: RetryPolicyM Identity -> RetryPolicyM IO purePolicyInIO = natTransformRetryPolicy (pure . runIdentity) 9retryXModify the delay of a RetryPolicy. Does not change whether or not a retry is performed.retryDConvert a boolean answer to the question "Should we retry?" into a .retryInitial, default retry status. Exported mostly to allow user code to test their handlers and retry policies. Use fields or lenses to update.retry;Apply policy on status to see what the decision would be. 7 implies no retry, : returns updated status.retryVApply policy and delay by its amount if it results in a retry. Return updated status.retryJHelper for making simplified policies that don't use the monadic context.retry"Retry immediately, but only up to n times.retryAdd 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 retryAdd 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.retry2Implement a constant delay with unlimited retries.retryWGrow delay exponentially each iteration. Each delay will increase by a factor of two.retryNFullJitter exponential backoff as explained in AWS Architecture Blog article. 7http://www.awsarchitectureblog.com/2015/03/backoff.html$temp = min(cap, base * 2 ** attempt).sleep = temp / 2 + random_between(0, temp / 2)retryImplement Fibonacci backoff.retrySet 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 maxDelayD between each one. To get termination you need to use one of the  function variants.retry~Retry combinator for actions that don't raise exceptions, but signal in their type the outcome has failed. Examples are the ;, < and EitherT monads.zLet's write a function that always fails and watch this combinator retry it 5 additional times following the initial run:import Data.Maybe5let f _ = putStrLn "Running action" >> return Nothing:retrying retryPolicyDefault (const $ return . isNothing) fRunning actionRunning actionRunning actionRunning actionRunning actionRunning actionNothingVNote how the latest failing result is returned after all retries have been exhausted. retrySame as r, but with the ability to override the delay of the retry policy based on information obtained after initiation.For example, if the action to run is a HTTP request that turns out to fail with a status code 429 ("too many requests"), the response may contain a "Retry-After" HTTP header which specifies the number of seconds the client should wait until performing the next request. This function allows overriding the delay calculated by the given retry policy with the delay extracted from this header value.#In other words, given an arbitrary   rpC, the following invocation will always delay by 1000 microseconds: GretryingDynamic rp (\_ _ -> return $ ConsultPolicyOverrideDelay 1000) f Note that a  s decision to not, perform a retry cannot be overridden. Ie. when to stopM retrying is always decided by the retry policy, regardless of the returned  value.!retryaRetry ALL exceptions that may be raised. To be used with caution; this matches the exception on =5. Note that this handler explicitly does not handle > nor ? (for versions of base >= 4.7). It is not a good idea to catch async exceptions as it can result in hanging threads and programs. Note that if you just throw an exception to this thread that does not descend from SomeException, recoverAll will not catch it._See how the action below is run once and retried 5 more times before finally failing for good:?let f _ = putStrLn "Running action" >> error "this is an error"recoverAll retryPolicyDefault fRunning actionRunning actionRunning actionRunning actionRunning actionRunning action*** Exception: this is an error"retry5List of pre-made handlers that will skip retries on > and ?. Append your handlers to this list as a convenient way to make sure you're not catching async exceptions like user interrupt.#retryRun an action and recover from a raised exception by potentially retrying the action a number of times. Note that if you're going to use a handler for =M, you should add explicit cases *earlier* in the list of handlers to reject > and ?9, as catching these can cause thread and program hangs. !< already does this for you so if you just plan on catching =, you may as well ues !$retry The difference between this and #) is the same as the difference between   and .%retry A version of # that tries to run the action only a single time. The control will return immediately upon both success and failure. Useful for implementing retry logic in distributed queues and similar external-interfacing systems.&retryLHelper function for constructing handler functions of the form required by #.'retry For use with &.(retryJRun given policy up to N iterations and gather results. In the pair, the Int! is the iteration number and the  Maybe Int is the delay in microseconds.)retryMRun given policy up to N iterations and pretty print results on the console.@retrySame as A on B but it maxes out at C :: B or D :: B rather than rolling overEretrySame as F on B but it maxes out at C :: B or D :: B rather than rolling overGretrySame as H on B but it maxes out at C :: B or D :: B rather than rolling overIretrySame as J on B but it maxes out at C :: B or MinBound :: B rather than rolling overretryMaximum number of retries.retry!Time-delay limit in microseconds.retry!Time-delay limit in microseconds.retryBase delay in microsecondsretryBase delay in microsecondsretryBase delay in microsecondsretryBase delay in microsecondsretryA maximum delay in microsecondsretrydAn action to check whether the result should be retried. If True, we delay and retry the operation.retry Action to run retryGAn action to check whether the result should be retried. The returned ? determines how/if a retry is performed. See documentation on .retry Action to run#retry Just use   for default settingsretryShould a given exception be retried? Action will be retried if this returns True *and* the policy allows it. This action will be consulted first even if the policy later blocks it.retryAction to perform$retry Just use   for default settingsretryTShould a given exception be retried? Action will be retried if this returns either  or f *and* the policy allows it. This action will be consulted first even if the policy later blocks it.retryAction to perform%retry Just use   for default settingsretryShould a given exception be retried? Action will be retried if this returns True *and* the policy allows it. This action will be consulted first even if the policy later blocks it.retry/Action to run with updated status upon failure.retry+Main action to perform with current status.retryCurrent status of this step&retry(Test for whether action is to be retriedretry_How to report the generated warning message. Boolean is whether it's being retried or crashed.retry Retry number*  !"#$%&'()*   #$%!"&'()K       !"#$%&'()*+,-./012345645745849:45;<49=49>4?@4AB4CD4CEF4GHIJK4LM4LNO4GPQ4RST4UVW$retry-0.8.1.2-HmOlrehu09M3GKTnDDCGfj Control.Retry RetryStatus rsIterNumberrsCumulativeDelayrsPreviousDelay RetryAction DontRetry ConsultPolicyConsultPolicyOverrideDelay RetryPolicy RetryPolicyMgetRetryPolicyMretryPolicyDefaultnatTransformRetryPolicy toRetryActiondefaultRetryStatus rsIterNumberLrsCumulativeDelayLrsPreviousDelayL applyPolicy applyAndDelay retryPolicy limitRetrieslimitRetriesByDelaylimitRetriesByCumulativeDelay constantDelayexponentialBackofffullJitterBackofffibonacciBackoffcapDelayretryingretryingDynamic recoverAllskipAsyncExceptions recoveringrecoveringDynamicstepping logRetries defaultLogMsgsimulatePolicysimulatePolicyPP$fMonoidRetryPolicyM$fSemigroupRetryPolicyM$fReadRetryAction$fShowRetryAction$fEqRetryAction$fGenericRetryAction$fReadRetryStatus$fShowRetryStatus$fEqRetryStatus$fGenericRetryStatusbaseGHC.BaseMonoidmappend<> GHC.MaybeNothingmemptymodifyRetryPolicyDelayJustMaybe Data.EitherEitherGHC.Exception.Type SomeExceptionGHC.IO.ExceptionAsyncExceptionSomeAsyncException boundedPlusGHC.Num+ghc-prim GHC.TypesIntGHC.EnummaxBoundminBound boundedMult* boundedSum Data.Foldablesum boundedPowGHC.Real^