Skip to content

Commit cd11187

Browse files
committed
Harden plugin notification handling
1 parent 154c991 commit cd11187

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

notifications/telegram.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
from notifications.events import NotificationPublisher, RenderedNotification
66

7+
try:
8+
from quant_platform_kit.common.notification_localization import (
9+
merge_strategy_plugin_i18n as _merge_strategy_plugin_i18n,
10+
)
11+
except ImportError: # pragma: no cover - compatibility with older pinned shared wheels
12+
_merge_strategy_plugin_i18n = None
13+
714

815
SIGNAL_ICONS = {
916
"hold": "💎",
@@ -131,7 +138,7 @@
131138
"strategy_plugin_name_macro_risk_governor": "宏观风险控制通知",
132139
"strategy_plugin_name_market_regime_control": "市场状态控制通知",
133140
"strategy_plugin_name_panic_reversal_shadow": "恐慌反转观察通知",
134-
"strategy_plugin_name_taco_rebound_shadow": "TACO 抄底观察通知",
141+
"strategy_plugin_name_taco_rebound_shadow": "TACO 反弹观察通知",
135142
"strategy_plugin_mode_shadow": "影子观察",
136143
"strategy_plugin_route_blocked": "已阻断",
137144
"strategy_plugin_route_crisis": "危机",
@@ -313,6 +320,9 @@
313320
},
314321
}
315322

323+
if _merge_strategy_plugin_i18n is not None:
324+
I18N = _merge_strategy_plugin_i18n(I18N)
325+
316326

317327
def build_translator(lang):
318328
def translate(key, **kwargs):
@@ -370,7 +380,7 @@ def send_tg_message(message):
370380
prefixed = with_prefix_fn(message)
371381
requests_module.post(url, json={"chat_id": chat_id, "text": prefixed}, timeout=10)
372382
except Exception as exc:
373-
print(f"Telegram send failed: {exc}", flush=True)
383+
print(f"Telegram send failed: {type(exc).__name__}", flush=True)
374384

375385
return send_tg_message
376386

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
flask
22
gunicorn
3-
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@c6e221f71d7be4d8b1c8c94ce05452c3116e0c10
3+
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@d26e8019a0d7d9f1947a0e11bf8829520db60c98
44
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@2b02dc947d99a593d2bbae4833f0eeeffc2eecd2
55
hk-equity-strategies @ git+https://github.com/QuantStrategyLab/HkEquityStrategies.git@5f739744b97d5a9f8981e7ae649c71a0a8ef10fa
66
pandas

scripts/cloud_run_runtime_guard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _send_telegram(message: str) -> bool:
208208
print(f"Telegram returned HTTP {response.status}", file=sys.stderr)
209209
except Exception as exc: # noqa: BLE001
210210
ok = False
211-
print(f"Telegram send failed: {exc}", file=sys.stderr)
211+
print(f"Telegram send failed: {type(exc).__name__}", file=sys.stderr)
212212
return ok
213213

214214

scripts/execution_report_heartbeat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def _send_telegram(message: str) -> bool:
653653
ok = ok and response.status < 400
654654
except Exception as exc: # noqa: BLE001
655655
ok = False
656-
print(f"Telegram send failed: {exc}", file=sys.stderr)
656+
print(f"Telegram send failed: {type(exc).__name__}", file=sys.stderr)
657657
return ok
658658

659659

0 commit comments

Comments
 (0)