💥 An Erlang library for breaking out of faulty services
Switch branches/tags
Nothing to show
Clone or download
aronisstav and zmstone Fix preservation/filtering of exceptions (#4)
This fixes a regression in OTP 20, due to the new format of
exceptions returned from processes spawned with proc_lib.
Latest commit e64b102 Jul 3, 2018


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.


rebar3 compile
rebar3 doc
rebar3 eunit


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

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

        % call timeout

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

        % timeout before reset in case of break

        %% 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, []}