mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 15:34:16 +08:00
Merge pull request #105 from im47cn/fix/task-reconnect-cleanup
fix(optimizer): SSE 放弃时清 localStorage + JSON 解析失败告警
This commit is contained in:
@@ -681,10 +681,13 @@ async def optimize_stream(
|
||||
try:
|
||||
base_params = json.loads(params) if params else {}
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
# 静默降级会让"用户配置丢失"变成无声 bug: 至少 warn 供诊断 (前端应传合法 JSON)。
|
||||
logger.warning("optimize: params JSON 解析失败, 降级为空 params: %r", params)
|
||||
base_params = {}
|
||||
try:
|
||||
ov = json.loads(overrides) if overrides else None
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
logger.warning("optimize: overrides JSON 解析失败, 降级为 None: %r", overrides)
|
||||
ov = None
|
||||
ocfg = OptimizeConfig(
|
||||
strategy_id=strategy_id,
|
||||
|
||||
@@ -174,6 +174,9 @@ function connectSSE(url: string): void {
|
||||
if (reconnectAttempts > MAX_RECONNECT) {
|
||||
es.close()
|
||||
eventSource = null
|
||||
// 清 localStorage: 否则刷新页面 tryReconnect 会重连到这个已放弃的任务。
|
||||
localStorage.removeItem(RECONNECT_KEY)
|
||||
localStorage.removeItem(JOB_KEY_KEY)
|
||||
current = { ...current, isPending: false, error: '连接中断, 重连多次失败' }
|
||||
emit()
|
||||
}
|
||||
@@ -244,9 +247,16 @@ export function stopOptimize(): void {
|
||||
localStorage.removeItem(RECONNECT_KEY)
|
||||
localStorage.removeItem(JOB_KEY_KEY)
|
||||
} else if (eventSource) {
|
||||
// 保持连接等 job 事件; 兜底: 5s 后仍没 key 就强关
|
||||
// 保持连接等 job 事件; 兜底: 5s 后仍没 key 就强关并清 localStorage,
|
||||
// 避免刷新重连到未取消任务。(若期间 job 到达, handler 已清并置 null, 下面条件不成立跳过)
|
||||
const es = eventSource
|
||||
setTimeout(() => { if (es === eventSource) { es.close(); eventSource = null } }, 5000)
|
||||
setTimeout(() => {
|
||||
if (es === eventSource) {
|
||||
es.close(); eventSource = null
|
||||
localStorage.removeItem(RECONNECT_KEY)
|
||||
localStorage.removeItem(JOB_KEY_KEY)
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
if (current?.isPending) {
|
||||
current = { ...current, isPending: false, error: '已取消' }
|
||||
|
||||
Reference in New Issue
Block a user