Liking cljdoc? Tell your friends :D

1. Configuration

Project Dependencies

resilience4clj-retry is distributed through Clojars with the identifier tessellator/resilience4clj-retry. You can find the version information for the latest release at https://clojars.org/tessellator/resilience4clj-retry.

Configuration Options

The following table describes the options available when configuring retrys as well as default values. A config is a map that contains any of the keys in the table. Note that a config without a particular key will use the default value (e.g., {} selects all default values).

Configuration OptionDefault ValueDescription
:max-attempts3The maximum number of retry attempts
:wait-duration500The fixed number of milliseconds to wait between attempts
:interval-function(constantly wait-duration)A function that receives the current number of attempts after a failure and returns the next wait duration
:retry-on-result-predicate(constantly false)A predicate that receives a result and determines whether it should be retried
:retry-on-exception-predicate(constantly true)A predicate that receives an exception and determines whether the result needs to be retried
:retry-exceptions[]A vector of exception types which should count as failures
:ignore-exceptions[]A vector of exception types which should not count as failures

There are a number of functions in this library that build interval functions including interval, randomized, exponential-backoff, and exponential-random-backoff. However, you may also create any function that receives the current number of attempts and returns a new wait duration.

A config can be used to configure the global registry or a retry when it is created.

Global Registry

This library creates a single global registry The registry may contain config values as well as retry instances.

configure-registry! overwrites the existing registry with one containing one or more config values. configure-registry! takes a map of name/config value pairs. When a retry is created, it may refer to one of these names to use the associated config. Note that the name :default (or "default") is special in that retrys that are created without a providing or naming a config with use this default config.

The function retry! will look up or create a retry in the global registry. The function accepts a name and optionally the name of a config or a config map.

(ns myproject.core
  (:require [resilience4clj.retry :as r])

;; The following creates two configs: the default config and the AttemptMoreTimes
;; config. The default config uses only the defaults and will be used to create
;; retrys that do not specify a config to use.
(r/configure-registry! {"default"    {}
                        "AttemptMoreTimes" {:max-attempts 5}})


;; create a retry named :name using the "default" config from the registry and
;; store the result in the registry
(r/retry! :name)

;; create a retry named :attempt-more using the "AttemptMoreTimes" config from
;; the registry and store the result in the registry
(r/retry! :attempt-more "AttemptMoreTimes")

;; create a retry named :custom-config using a custom config map and store the
;; result in the registry
(r/retry! :custom-config {:max-attempts 5
                          :wait-duration 1000})

Custom Retrys

While convenient, it is not required to use the global registry. You may instead choose to create retrys and manage them yourself.

In order to create a retry that is not made available globally, use the retry function, which accepts a name and config map.

The following code creates a new retry with the default config options.

(ns myproject.core
  (:require [resilience4clj.retry :as r]))

(def my-retry (r/retry :my-retry {}))

Can you improve this documentation?Edit on GitHub

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

× close