Liking cljdoc? Tell your friends :D

again.core


additive-strategyclj

(additive-strategy increment)
(additive-strategy initial-delay increment)

Returns a retry strategy where, after the initial-delay (ms), the delay increases by increment (ms) after each retry. The single argument version uses the given increment as both the initial delay and the increment.

Returns a retry strategy where, after the `initial-delay` (ms), the delay
increases by `increment` (ms) after each retry. The single argument version
uses the given increment as both the initial delay and the increment.
sourceraw docstring

clamp-delayclj

(clamp-delay delay retry-strategy)

Replace delays in the strategy that are larger than delay with delay.

Replace delays in the strategy that are larger than `delay` with
`delay`.
sourceraw docstring

constant-strategyclj

(constant-strategy delay)

Generates a retry strategy with a constant delay (ms) between attempts, ie the delay is the same for each retry.

Generates a retry strategy with a constant delay (ms) between attempts, ie the
delay is the same for each retry.
sourceraw docstring

immediate-strategyclj

(immediate-strategy)

Returns a retry strategy that retries without any delay.

Returns a retry strategy that retries without any delay.
sourceraw docstring

max-delayclj

(max-delay delay retry-strategy)

Stop retrying once the a delay is larger than delay.

Stop retrying once the a delay is larger than `delay`.
sourceraw docstring

max-durationclj

(max-duration timeout retry-strategy)

Stop retrying once the sum of past delays exceeds timeout (ms). Note: the sum considers only the delays in the strategy, any time spent on executing the operation etc is not included (that is, we're not measuring wallclock time here).

Stop retrying once the sum of past delays exceeds `timeout` (ms). Note: the sum
considers only the delays in the strategy, any time spent on executing the
operation etc is not included (that is, we're not measuring wallclock time
here).
sourceraw docstring

max-retriesclj

(max-retries n retry-strategy)

Stop retrying after n retries.

Stop retrying after `n` retries.
sourceraw docstring

multiplicative-strategyclj

(multiplicative-strategy initial-delay delay-multiplier)

Returns a retry strategy with exponentially increasing delays, ie each previous delay is multiplied by delay-multiplier to generate the next delay.

Returns a retry strategy with exponentially increasing delays, ie each previous
delay is multiplied by `delay-multiplier` to generate the next delay.
sourceraw docstring

randomize-strategyclj

(randomize-strategy rand-factor retry-strategy)

Returns a retry strategy where all the delays have been scaled by a random number between [1 - rand-factor, 1 + rand-factor]. rand-factor must be greater than 0 and less than 1.

Returns a retry strategy where all the delays have been scaled by a random
number between [1 - `rand-factor`, 1 + `rand-factor`]. `rand-factor` must be
greater than 0 and less than 1.
sourceraw docstring

stop-strategyclj

(stop-strategy)

A no-retries policy.

A no-retries policy.
sourceraw docstring

with-retriescljmacro

(with-retries strategy-or-options & body)

Try executing body. If body throws an Exception, retry according to the retry strategy.

A retry strategy is a seq of delays: with-retries will sleep the duration of the delay (in ms) before each retry. The total number of attempts is the number of elements in the strategy plus one. A simple retry stategy would be: [100 100 100 100] which results in the operation being retried four times, for a total of five attempts, with 100ms sleeps in between attempts. Note: that infinite strategies are supported, but maybe not encouraged…

Strategies can be built with the provided builder fns, eg linear-strategy, and modified with the provided manipulator fns, eg clamp-delay, but you can also create any custom seq of delays that suits your use case.

Instead of a simple delay sequence, you can also pass in the following type of options map:

{:again.core/callback <fn> :again.core/user-context <anything, but probably an atom> :again.core/strategy <delay strategy>}

:again.core/callback is a callback function that is called after each attempt. :again.core/user-context is an opaque value that is passed to the callback function as an argument. And :again.core/strategy is the sequence of delays.

The callback function is called with the following type of map as its only argument:

{:again.core/attempts <the number of attempts thus far> :again.core/exception <the exception thrown by body> :again.core/slept <the sum of all delays thus far> :again.core/status <the result of the last attempt: :success, :failure, or :retry :again.core/user-context <the user context from the options map>}

Try executing `body`. If `body` throws an `Exception`, retry according to the
retry `strategy`.

A retry `strategy` is a seq of delays: `with-retries` will sleep the duration
of the delay (in ms) before each retry. The total number of attempts is the
number of elements in the `strategy` plus one. A simple retry stategy would
be: [100 100 100 100] which results in the operation being retried four times,
for a total of five attempts, with 100ms sleeps in between attempts. Note:
that infinite strategies are supported, but maybe not encouraged…

Strategies can be built with the provided builder fns, eg `linear-strategy`,
and modified with the provided manipulator fns, eg `clamp-delay`, but you can
also create any custom seq of delays that suits your use case.

Instead of a simple delay sequence, you can also pass in the following type of
options map:

{:again.core/callback <fn>
 :again.core/user-context <anything, but probably an atom>
 :again.core/strategy <delay strategy>}

`:again.core/callback` is a callback function that is called after each
attempt. `:again.core/user-context` is an opaque value that is passed to the
callback function as an argument. And `:again.core/strategy` is the sequence
of delays.

The callback function is called with the following type of map as its only
argument:

{:again.core/attempts <the number of attempts thus far>
 :again.core/exception <the exception thrown by body>
 :again.core/slept <the sum of all delays thus far>
 :again.core/status <the result of the last attempt: :success, :failure, or :retry
 :again.core/user-context <the user context from the options map>}
sourceraw docstring

with-retries*clj

(with-retries* strategy-or-options f)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close