(calculate-retry-delay response attempt)Calculates retry delay, preferring Stripe's Retry-After header if present. Falls back to exponential backoff with jitter.
Parameters:
Returns: The delay in milliseconds before retrying.
Calculates retry delay, preferring Stripe's Retry-After header if present. Falls back to exponential backoff with jitter. Parameters: - response: The HTTP response map (may contain Retry-After header). - attempt: The current retry attempt (zero-indexed). Returns: The delay in milliseconds before retrying.
(exponential-backoff-delay attempt)Calculates exponential backoff delay with jitter (pure function).
The delay is calculated as follows:
exponential-delay: Grows exponentially as base-delay * (2^attempt).jitter: A random number up to half of the exponential delay, to help distribute retries
and avoid a thundering herd situation.Parameters:
Returns: The calculated delay in milliseconds.
Calculates exponential backoff delay with jitter (pure function). The delay is calculated as follows: - `exponential-delay`: Grows exponentially as base-delay * (2^attempt). - `jitter`: A random number up to half of the exponential delay, to help distribute retries and avoid a thundering herd situation. - The final delay is capped at max-delay-ms (20000 ms). Parameters: - attempt: The current retry attempt (zero-indexed). Returns: The calculated delay in milliseconds.
(parse-retry-after-header response)Parses Retry-After header value to milliseconds.
Stripe sends the Retry-After header as seconds (integer).
Parameters:
Returns: The retry delay in milliseconds, or nil if header is missing or unparseable.
Parses Retry-After header value to milliseconds. Stripe sends the Retry-After header as seconds (integer). Parameters: - response: The HTTP response map with :headers. Returns: The retry delay in milliseconds, or nil if header is missing or unparseable.
(with-retry f max-retries)Wraps a function with retry logic that respects Stripe's Retry-After header.
The provided function, f, is expected to return a map that includes a :status key.
If the returned status is retryable (as determined by retryable-status?),
the function will wait and retry the operation.
Retry delay is determined by:
The process repeats until a non-retryable status is returned or the maximum number of
retries (max-retries) is reached.
Parameters:
:status key.Returns:
A new function wrapping f. When called, it will:
f with the provided arguments.max-retries, wait using
Retry-After header or exponential backoff, then retry.Wraps a function with retry logic that respects Stripe's Retry-After header.
The provided function, `f`, is expected to return a map that includes a `:status` key.
If the returned status is retryable (as determined by `retryable-status?`),
the function will wait and retry the operation.
Retry delay is determined by:
1. Stripe's Retry-After header (if present) - converted from seconds to milliseconds
2. Exponential backoff with jitter (fallback)
The process repeats until a non-retryable status is returned or the maximum number of
retries (`max-retries`) is reached.
Parameters:
- f: A function to be executed that returns a map with at least a `:status` key.
- max-retries: The maximum number of retry attempts (non-negative integer).
Returns:
A new function wrapping `f`. When called, it will:
1. Execute `f` with the provided arguments.
2. Check if the result contains a retryable status.
3. If retryable and the attempt count is less than `max-retries`, wait using
Retry-After header or exponential backoff, then retry.
4. Otherwise, return the most recent result.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |