sunng87 / diehard

Clojure resilience library for flexible retry, circuit breaker and rate limiter
Eclipse Public License 2.0
330 stars 27 forks source link

Document types and arity of circuit breaker options #28

Open marcomorain opened 4 years ago

marcomorain commented 4 years ago

First of all, thank you for diehard 🙏

I'm having a hard time setting up some of the circuit breaker options. In particular, the following keys are documented, but not what type the values should be. In particular, I don't know what the value should be for the following:

I assume that :on-open, :on-close, :on-half-open should be functions of artity 0.

Diehard docs: https://cljdoc.org/d/diehard/diehard/0.8.5/api/diehard.core#defcircuitbreaker

Define a circuit breaker with option.

Available options

There options are available when creating circuit breaker in defcircuitbreaker.

Failure criteria

All the three fail options share same meaning with similar option in retry block.

  • :fail-if
  • :fail-on
  • :fail-when
  • :timeout-ms while give all you code a timeout is best practice in application level, circuit breaker also provides a timeout for marking a long running block as failure
Delay and threshold
  • :delay-ms required. the delay for :open circuit breaker to turn into :half-open.
  • :failure-threshold
  • :failure-threshold-ratio
  • :success-threshold
  • :success-threshold-ratio All these four option is to determine at what condition the circuit breaker is open.
Listeners
  • :on-open a function to be called when state goes :open
  • :on-close a function to be called when state goes :closed
  • :on-half-open a function to be called when state goes :half-open

Failsafe docs: https://jodah.net/failsafe/circuit-breaker/#event-listeners

In addition to the standard policy listeners, a CircuitBreaker can notify you when the state of the breaker changes:

circuitBreaker
 .onOpen(() -> log.info("The circuit breaker was opened"))
 .onClose(() -> log.info("The circuit breaker was closed"))
 .onHalfOpen(() -> log.info("The circuit breaker was half-opened"));
sunng87 commented 4 years ago

Sorry for inconvenience. Could you please send a pull request for this?