eleme / doctor Goto Github PK
View Code? Open in Web Editor NEWMetric based in-memory circuit breaker for python
License: MIT License
Metric based in-memory circuit breaker for python
License: MIT License
Hi, 代码里把当前接口的状态的判断和当前请求处理方式的判断放到一起,我觉得是不是不太合适。
当前接口的状态由如下三个条件决定:
而当前请求的处理方式决定规则如下:
MODE_LOCKED
都是 FalseMODE_UNLOCKED
都是 TrueMODE_RECOVER
MODE_LOCKED
转换过来,那么是 Truebool(random.random() < float(locked_span) / self._max_recovery_time)
如果先判断当前接口的状态再判断请求的处理方式,则整个逻辑会看上去简单的多:
locked_span = time_now - locked_at
if (locked_status == MODE_LOCKED and
health_ok_now and
locked_span >= self._min_recovery_time):
# enter into recover mode
lock['locked_status'] = MODE_RECOVER
lock_changed = MODE_RECOVER
elif locked_status == MODE_RECOVER:
if self._metrics.api_latest_state.get(key, False):
if locked_span >= self._max_recovery_time:
lock['locked_at'] = 0
lock['locked_status'] = MODE_UNLOCKED
lock_changed = MODE_UNLOCKED
else:
# still suffering, lock it again
lock['locked_at'] = time_now
lock['locked_status'] = MODE_LOCKED
lock_changed = MODE_LOCKED
elif locked_status == MODE_UNLOCKED and \
not health_ok_now:
# turns BAD
lock['locked_at'] = time_now
lock['locked_status'] = MODE_LOCKED
lock_changed = MODE_LOCKED
current_locked_status = lock['locked_status']
if current_locked_status == MODE_LOCKED:
result = False
elif current_locked_status == MODE_UNLOCKED:
result = True
elif current_locked_status == MODE_RECOVER:
if lock_changed is not None:
# one request will be released for health checking once
# this api enters recover mode
result = True
else:
result = bool(random.random() <
float(locked_span) / self._max_recovery_time)
description="", 这个可以直接把 readme 搞进来.
url=''" 这个用 github 地址\
author='Eleme Dev', => 这个有 wangchao, wangxiangyu, 等等. 可以看看 git st 的状况.
author_email='', => 这个填你和王超的邮箱.
以上每个情形一个用例。
另外注意PEP8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.