Git Product home page Git Product logo

Comments (3)

phillbaker avatar phillbaker commented on July 17, 2024

I think this is related to #15.

What we ended up doing is similar to:

BREAKER = CircuitBreaker(...)
...
    def active(self):
        timeout = timedelta(seconds=BREAKER.reset_timeout)
        timeout_active = not hasattr(BREAKER.state, 'opened_at') or \
            hasattr(BREAKER.state, 'opened_at') and datetime.now() < BREAKER.state.opened_at + timeout
        return BREAKER.current_state == 'closed' or not timeout_active

from pybreaker.

danielfm avatar danielfm commented on July 17, 2024

Closed by #27, feel free to re-open this if you have problems.

from pybreaker.

vt-iwamoto avatar vt-iwamoto commented on July 17, 2024

I started using this patch. It seems to work fine for now.

import pybreaker

def circuit_breaker_open(self):
    with self._lock:
        self.state = self._state_storage.state = pybreaker.STATE_OPEN
        self._state_storage.opened_at = pybreaker.datetime.utcnow()

def circuit_open_state_init(self, cb, prev_state=None, notify=False):
    super(pybreaker.CircuitOpenState, self).__init__(cb, pybreaker.STATE_OPEN)
    try:
        _ = self._breaker._state_storage.opened_at
    except:
        self._breaker._state_storage.opened_at = pybreaker.datetime.utcnow()
    if notify:
        for listener in self._breaker.listeners:
            listener.state_change(self._breaker, prev_state, self)

pybreaker.CircuitBreaker.open = circuit_breaker_open
pybreaker.CircuitOpenState.__init__ = circuit_open_state_init

from pybreaker.

Related Issues (20)

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.