Coder Social home page Coder Social logo

breaky's Introduction

Breaky

Breaky provides a way to supervise and manage modules and processes depending on external resources. For these kind of processes standard OTP supervisors will not work. The problem is that if something fails, the supervisor can't return the state of an external process into a known good state by restarting. The supervisor has no control over it. When that happens too often, the supervisor will fail too, and if a supervisor is restarted often enough it can take down the whole system down.

Circuit Breaker Photo by leafbug

Breaky acts as a automatic circuit breaker "middleman" for these kind of processes. The process are started and managed in a normal OTP supervision tree. Restarts are managed by a circuit breaker FSM. When the FSM detects too many failures it will try to re-establish the service, but when a certaint threshold of restarts has been reached the restarts will be done in a slower rate and calls or casts to the failing process will result in off to notify that the circuit breaker is off and the process is not available. This will prevent the fault from cascading through the system.

Example:

    %% Start the circuit breaker for the database. It is an external resource.
    Args = [{user, "me"}, {password, "1234"}],
    {ok, _Pid} = breaky:start_circuit_breaker(db, {database, start_link, Args}),
 
    ...
    
    case breaky:call(db, "select * from my_table;") of
        off ->
            error_logger:error_msg("database unavailable"); 
            {error, db_unavailable};
        {ok, Result} ->
            Result
    end,
    ...

Circuit Breaker States

State Description
Off The service is not available
On The service is running normally

breaky's People

Contributors

loucash avatar mmzeeman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.