Struct failsafe::StateMachine

source ·
pub struct StateMachine<POLICY, INSTRUMENT> { /* private fields */ }
Expand description

A circuit breaker implementation backed by state machine.

It is implemented via a finite state machine with three states: Closed, Open and HalfOpen. The state machine does not know anything about the backend’s state by itself, but uses the information provided by the method via on_success and on_error events. Before communicating with the backend, the the permission to do so must be obtained via the method is_call_permitted.

The state of the state machine changes from Closed to Open when the FailurePolicy reports that the failure rate is above a (configurable) threshold. Then, all access to the backend is blocked for a time duration provided by FailurePolicy.

After the time duration has elapsed, the state changes from Open to HalfOpen and allows calls to see if the backend is still unavailable or has become available again. If the circuit breaker receives a failure on the next call, the state will change back to Open. Otherwise it changes to Closed.

Implementations

Creates a new state machine with given failure policy and instrument.

Requests permission to call.

It returns true if a call is allowed, or false if prohibited.

Records a successful call.

This method must be invoked when a call was success.

Records a failed call.

This method must be invoked when a call failed.

Trait Implementations

Requests permission to call. Read more
Executes a given function within circuit breaker. Read more
Executes a given function within circuit breaker. Read more
Requests permission to call. Read more
Executes a given future within circuit breaker. Read more
Executes a given future within circuit breaker. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.