!w)      !"#$%&'((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.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 )7. You can collapse multiple strategies into one using * or +4. The semantics of this combination are as follows: If either policy returns ,, the combined policy returns ,. 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, -d will retry immediately (delay 0) for an unlimited number of retries, forming the identity for the ).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 policy retryWApplies 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) 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. , 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 /, 0 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.retryaRetry ALL exceptions that may be raised. To be used with caution; this matches the exception on 15. Note that this handler explicitly does not handle 2 nor 3 (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 errorretry5List of pre-made handlers that will skip retries on 2 and 3. 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 1M, you should add explicit cases *earlier* in the list of handlers to reject 2 and 39, as catching these can cause thread and program hangs. < already does this for you so if you just plan on catching 1, you may as well ues 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.4retrySame as 5 on 6 but it maxes out at 7 :: 6 or 8 :: 6 rather than rolling over9retrySame as : on 6 but it maxes out at 7 :: 6 or 8 :: 6 rather than rolling over;retrySame as < on 6 but it maxes out at 7 :: 6 or 8 :: 6 rather than rolling over=retrySame as > on 6 but it maxes out at 7 :: 6 or MinBound :: 6 rather than rolling over retryMaximum 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 runretry 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 performretry 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 stepretry(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#  !"#    !"?      !"#$%&'()*+)*,)*-)./)*0).1).2)34)56)78)79:);<=>?)@A)@BC);DE)FGH)IJK$retry-0.8.0.2-4Q2AwwrGOIVK1Yda7Efrty Control.Retry RetryStatus rsIterNumberrsCumulativeDelayrsPreviousDelay RetryPolicy RetryPolicyMgetRetryPolicyMretryPolicyDefaultnatTransformRetryPolicydefaultRetryStatus rsIterNumberLrsCumulativeDelayLrsPreviousDelayL applyPolicy applyAndDelay retryPolicy limitRetrieslimitRetriesByDelaylimitRetriesByCumulativeDelay constantDelayexponentialBackofffullJitterBackofffibonacciBackoffcapDelayretrying recoverAllskipAsyncExceptions recoveringstepping logRetries defaultLogMsgsimulatePolicysimulatePolicyPP$fMonoidRetryPolicyM$fSemigroupRetryPolicyM$fReadRetryStatus$fShowRetryStatus$fEqRetryStatus$fGenericRetryStatusbaseGHC.BaseMonoidmappend<> GHC.MaybeNothingmemptyJustMaybe Data.EitherEitherGHC.Exception.Type SomeExceptionGHC.IO.ExceptionAsyncExceptionSomeAsyncException boundedPlusGHC.Num+ghc-prim GHC.TypesIntGHC.EnummaxBoundminBound boundedMult* boundedSum Data.Foldablesum boundedPowGHC.Real^