refactor(notify): 新增通知中间层, 8 个脚本渠道扇出去重 - #417
Open
1w1w11w1 wants to merge 1 commit into
Open
Conversation
新增 app/services/notify_dispatch.py 承接渠道扇出: NotifyPayload 只描述 「一份已渲染的报告」, NotifyTarget 描述「推给谁」, 用户级与脚本级的差异 收敛成 targets 列表, 各脚本只保留自己独有的正文构造与模板选择。 顺带修掉两处行为问题: - 单渠道失败不再中断后续渠道 (此前仅 M9A 有隔离, 其余 7 个脚本一炸全停) - push_notification 返回失败渠道列表, 管理器据此决定是否消费签到汇总, 避免推送失败时汇总被误标为已发送而丢失 以 characterization test 兜底: 8 脚本 x 10 场景 x 5 mode 的渠道调用序列 与重构前逐字节比对, 413 项不变, 21 项差异全部落在 _channel_failure, 即上述有意变更的失败隔离行为。
审查者指南本 PR 新增通知分发中间层,将 8 个脚本重复的渠道扇出、格式转换和错误处理集中复用,同时保留各脚本正文与模板差异;通知入口现返回失败渠道列表,管理器据此避免在部分发送失败时丢失签到汇总,并以跨脚本 characterization baseline 验证非预期行为未变。 隔离通知渠道失败的时序图sequenceDiagram
participant Manager
participant NotifyTool
participant Dispatch as notify_dispatch
participant Mail
participant ServerChan
participant Webhook
Manager->>NotifyTool: push_notification
NotifyTool->>Dispatch: dispatch(payload, targets)
Dispatch->>Mail: send_mail
Mail-->>Dispatch: failure
Dispatch->>ServerChan: ServerChanPush
ServerChan-->>Dispatch: success
Dispatch->>Webhook: WebhookPush
Webhook-->>Dispatch: success
Dispatch-->>NotifyTool: failed channel list
NotifyTool-->>Manager: failed channel list
通知失败后保留签到汇总的时序图sequenceDiagram
participant Manager
participant NotifyTool
participant Dispatch as notify_dispatch
participant Channels
participant Summary
Manager->>NotifyTool: push_notification
NotifyTool->>Dispatch: dispatch(payload, targets)
Dispatch->>Channels: send channels independently
Channels-->>Dispatch: failed channel list
Dispatch-->>NotifyTool: failed channel list
NotifyTool-->>Manager: failed channel list
alt failed channel list is empty
Manager->>Summary: mark_task_game_sign_summary_consumed
else channel failure
Manager-->>Summary: retain summary for a later report
end
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的控制面板:
获取帮助Original review guide in EnglishReviewer's Guide本 PR 新增通知分发中间层,将 8 个脚本重复的渠道扇出、格式转换和错误处理集中复用,同时保留各脚本正文与模板差异;通知入口现返回失败渠道列表,管理器据此避免在部分发送失败时丢失签到汇总,并以跨脚本 characterization baseline 验证非预期行为未变。 Sequence diagram for isolated notification channel failuressequenceDiagram
participant Manager
participant NotifyTool
participant Dispatch as notify_dispatch
participant Mail
participant ServerChan
participant Webhook
Manager->>NotifyTool: push_notification
NotifyTool->>Dispatch: dispatch(payload, targets)
Dispatch->>Mail: send_mail
Mail-->>Dispatch: failure
Dispatch->>ServerChan: ServerChanPush
ServerChan-->>Dispatch: success
Dispatch->>Webhook: WebhookPush
Webhook-->>Dispatch: success
Dispatch-->>NotifyTool: failed channel list
NotifyTool-->>Manager: failed channel list
Sequence diagram for preserving sign-in summaries after notification failuresequenceDiagram
participant Manager
participant NotifyTool
participant Dispatch as notify_dispatch
participant Channels
participant Summary
Manager->>NotifyTool: push_notification
NotifyTool->>Dispatch: dispatch(payload, targets)
Dispatch->>Channels: send channels independently
Channels-->>Dispatch: failed channel list
Dispatch-->>NotifyTool: failed channel list
NotifyTool-->>Manager: failed channel list
alt failed channel list is empty
Manager->>Summary: mark_task_game_sign_summary_consumed
else channel failure
Manager-->>Summary: retain summary for a later report
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
app/services/notify_dispatch.py作为通知中间层承接渠道扇出:NotifyPayload描述「一份已渲染的报告」,NotifyTarget描述「推给谁」。用户级与脚本级报告的差异收敛成一个 targets 列表,8 个脚本的tools/notify.py只保留自己独有的正文构造与模板选择,共减少 863 行、新增 338 行。push_notification改为返回失败渠道列表,8 个管理器据此决定是否消费签到汇总,不再在发送失败后把汇总误标为已推送。测试
以 characterization test 兜底(
tests/task/test_notify_channels_parity.py):录制 8 脚本 × 10 场景 × 5 mode 下对各渠道的调用序列,与重构前的基线逐字节比对。413 项完全不变,21 项差异全部落在_channel_failure,即上述有意变更的失败隔离行为;M9A 不在差异列表中,印证它原本就有隔离。已运行:
tests/task/test_notify_channels_parity.py、tests/services/test_notification.py、tests/task/test_okww_manual_stop_history.py、tests/task/test_maa_statistics.py—— 13 passed。tests/tools/test_game_sign_notification.py有 6 项失败,与本 PR 无关:origin/dev上append_task_game_sign_summary(task_info, result)的签名与其测试传的uncompleted_count=不符,已在origin/dev的干净检出上复现同样的 6 项失败,本 PR 未改动这两个文件。未包含
前端仍有一份同构的重复(4 份近乎相同的
NotifyConfigSection.vue+ General/Okww/OkNte 三份内联副本;HSR 后端配置齐全但没有通知 UI;除HSRUserConfig_Notify外 7 个用户 Notify schema 漏了CustomWebhooks;用户级 webhook 没有 test 端点)。与后端解耦,留作后续 PR。Sourcery 摘要
在所有脚本之间集中处理通知发送,同时改进故障隔离,防止推送失败导致登录摘要丢失。
新功能:
错误修复:
增强功能:
测试:
Original summary in English
Summary by Sourcery
Centralize notification delivery across all scripts while improving failure isolation and preventing failed pushes from losing sign-in summaries.
New Features:
Bug Fixes:
Enhancements:
Tests: