🐛 B站请求策略阶段行为优化 (#610)

* 🐛 调整ruff的pytest警告

* 🐛 调整导入关系警告

* 🐛 删除奇怪无用的赋值和取值逻辑

*  不同测试部分所用变量应加以区分

* 🐛 subs_io model添加默认值

* 🐛 修完所有的 ruff PT001 警告

* 🔧 按ruff建议修改ruff配置

warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'

* 🔊 降低B站请求策略非Raise阶段API352的日志等级

* 🐛 Raise阶段应该 raise err

* 🔊 日志添加平台名

* 🐛 bzhanhan调度继续降低至60s

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Azide 2024-09-01 22:30:02 +08:00 committed by GitHub
parent afcc536334
commit b8b49a5ce5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -236,15 +236,19 @@ def retry_for_352(api_func: Callable[[TBilibili, Target], Awaitable[list[DynRawP
case RetryState.NROMAL | RetryState.REFRESH | RetryState.RAISE:
try:
res = await api_func(bls, *args, **kwargs)
except ApiCode352Error:
logger.error("API 352 错误")
except ApiCode352Error as e:
logger.warning("本次 Bilibili API 请求返回 352 错误码")
await _retry_fsm.emit(RetryEvent.REQUEST_AND_RAISE)
if _retry_fsm.current_state == RetryState.RAISE:
raise e
return []
else:
await _retry_fsm.emit(RetryEvent.REQUEST_AND_SUCCESS)
return res
case RetryState.BACKOFF:
logger.warning("回避中,不请求")
logger.warning("本次 Bilibili 请求回避中,不请求")
await _retry_fsm.emit(RetryEvent.IN_BACKOFF_TIME)
return []
case _:

View File

@ -68,7 +68,7 @@ class BilibiliClientManager(ClientManager):
class BilibiliSite(Site):
name = "bilibili.com"
schedule_setting = {"seconds": 50}
schedule_setting = {"seconds": 60}
schedule_type = "interval"
client_mgr = BilibiliClientManager
require_browser = True

View File

@ -183,7 +183,7 @@ async def test_retry_for_352(app: App, mocker: MockerFixture):
fakebili.set_raise352(True)
for state in test_state_list:
for state in test_state_list[:-3]:
logger.info(f"\n\nnow state should be {state}")
assert _retry_fsm.current_state == state
@ -194,6 +194,13 @@ async def test_retry_for_352(app: App, mocker: MockerFixture):
if state == RetryState.BACKOFF:
freeze_start += timedelta_length * (_retry_fsm.addon.backoff_count + 1) ** 2
for state in test_state_list[-3:]:
logger.info(f"\n\nnow state should be {state}")
assert _retry_fsm.current_state == state
with pytest.raises(ApiCode352Error):
await fakebili.get_sub_list(Target("t1")) # type: ignore
assert client_mgr.refresh_client_call_count == 4 * 3 + 3 # refresh + raise
assert client_mgr.get_client_call_count == 2 + 4 * 3 + 3 # previous + refresh + raise