refactor(notifications): deduplicate AlertMarkerStore + add pluggable channel Protocols - #121
Merged
Merged
Conversation
…x duplicated code
- New alert_marker.py: shared CloudAlertMarkerStore base class with
has_alert/record_alert/_local_path/_cloud_uri + _clean_relative_key helper
- strategy_plugin_{email,sms,push,telegram}.py: replace ~55-line duplicate
marker store classes with thin 3-line subclasses (~200 lines removed)
- All 4 classes preserved (backward compat), just inherit from base now
Also removes 4 duplicate _clean_relative_key + _parse_cloud_uri helpers
(now in alert_marker.py which correctly supports gs://, s3://, and az://).
373 passed, 0 failed.
Co-Authored-By: Claude <noreply@anthropic.com>
- channel.py: define SmsChannel, PushChannel, EmailChannel, ChatChannel Protocols - 5 default implementations: TwilioSmsChannel, PushoverChannel, NtfyChannel, SmtpEmailChannel, TelegramChatChannel — thin wrappers around existing functions - Users can now swap providers by implementing a Protocol and passing it as send_notification to publish_strategy_plugin_*_alerts() - Export all channels from notifications/__init__.py This completes the notification decoupling: previously Twilio/Pushover/SMTP/Telegram were hardcoded; now any provider implementing the Protocol can be dropped in. 373 passed, 0 failed. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
通知模块两项重构:消除重复代码 + 添加可插拔渠道 Protocol。
1. 消除 4x 重复的 AlertMarkerStore(-164 行)
新增
alert_marker.py,抽取共享的CloudAlertMarkerStore基类:has_alert()/record_alert()/_local_path()/_cloud_uri()统一实现_clean_relative_key和_parse_cloud_uri统一到基类(同时支持 gs://, s3://, az://)StrategyPlugin*AlertMarkerStore从 ~55 行缩减为 3 行子类改动前(4 个文件各 55 行重复):
改动后:
2. 可插拔通知渠道 Protocol
新增
channel.py,定义 4 个 Protocol + 5 个默认实现:SmsChannelTwilioSmsChannelPushChannelPushoverChannel+NtfyChannelEmailChannelSmtpEmailChannelChatChannelTelegramChatChannel替换示例:
Testing
Breaking Changes
None. All existing public APIs preserved.