Skip to content

klarna/circuit_breaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Generic circuit breaker that can be used to break any service that isn't fully functional. A service can be manually blocked/cleared as well.

See doc/overview.edoc for more info.

Building

rebar3 compile
rebar3 doc
rebar3 eunit

Using

%% Circuit-breaking
call(State, SomeId) ->
    circuit_breaker:call(
        % service identifier for the circuit
        {myservice, SomeId},

        % function being monitored
        fun() -> some_call(State) end,

        % call timeout
        timer:minutes(1),

        % reset fun, just returns true
        fun() -> true end,

        % timeout before reset in case of break
        timer:minutes(5),

        %% Options
        [
            % Number of errors tolerated per unit of time.
            {n_error, 3},
            {time_error, timer:minutes(30)},

            %% number of calls returning 'timeout' tolerated in a given
            %% period of time.
            {n_timeout, 3},
            % interval to happen
            {time_timeout, timer:minutes(30)},

            %% number of calls not responding in due time tolerated, and
            %% the time interval for the N failures to happen
            {n_call_timeout, 3},
            {time_call_timeout, timer:minutes(25)},

            %% When failing, the {'EXIT', Reason} tuple will be returned from
            %% the call. This list of `Reason's allows to avoid counting specific
            %% errors towards thresholds that can break a circuit.
            {ignore_errors, []}
        ]
    ).

About

💥 An Erlang library for breaking out of faulty services

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages