-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bilibili调度新增回避策略 #573
Bilibili调度新增回避策略 #573
Conversation
✅ Deploy Preview for nonebot-bison ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #573 +/- ##
==========================================
+ Coverage 85.01% 85.39% +0.38%
==========================================
Files 88 90 +2
Lines 4491 4718 +227
==========================================
+ Hits 3818 4029 +211
- Misses 673 689 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
f3bfa96
to
822622d
Compare
设想的状态转换图 stateDiagram-v2
direction LR
[*] --> NORMAL
NORMAL --> NORMAL: 请求成功
NORMAL --> REFRESH: 请求失败
REFRESH --> NORMAL: 请求成功
REFRESH --> REFRESH: 请求失败
REFRESH --> BACKOFF: 请求失败 若重试满但回避未满
REFRESH --> RAISE: 请求失败 若重试满且回避满
BACKOFF --> BACKOFF: 回避中
BACKOFF --> REFRESH: 回避中 若已超时
RAISE --> RAISE: 请求失败
RAISE --> NORMAL: 请求成功
修改记录: |
bef83cb
to
ba3df50
Compare
用生成器正经搓了个小状态机,感觉这样看起来更清晰一点 |
return waited < should_wait | ||
|
||
|
||
B = TypeVar("B", bound="Bilibili") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是不是没啥必要
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不这样写的话retry_for_352
的类型得全用引号包起来(
a879824
to
d5bd87f
Compare
|
||
|
||
class RetryState(StrEnum): | ||
NROMAL = "normal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NORMAL
self.graph = graph | ||
self.current_state = graph["initial"] | ||
self.machine = self.core() | ||
self.ctx = ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个叫 additional state 吧
self.machine = self.core() | ||
self.ctx = ctx | ||
|
||
async def core(self) -> AsyncGenerator[ActionReturn, TEvent]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async def core(self) -> AsyncGenerator[ActionReturn, TEvent]: | |
async def _core(self) -> AsyncGenerator[ActionReturn, TEvent]: |
await fsm.emit(RetryEvent.REACH_MAX_REFRESH) | ||
case RetryActionReturn.BACKOFF_MAX: | ||
logger.error("指数回避次数达到上限,放弃回避") | ||
await fsm.emit(RetryEvent.REACH_MAX_BACKOFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方太奇怪了,要根据 fsm 返回的结果 emit 特定事件,你这个自动机改叫手动机好了
原先的30s对叔叔而言还是太敏感了