fix(wle): 钉钉推送失败后自动重试,不再「一天只有一次机会」 #96
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "yanhui-wle-notify-retry-1111"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
目的
11-11 09:10 的「仓储物流转运异常」推送没进群。查下来不是通道坏,是业务库当时连不上:
system_config.warehouse_logistics_exception_notify_state里lastFailedAt = 2026-11-11 09:12:57、lastError = "Failed to connect to 218.93.9.21:1433"、lastSentDate还停在2026-11-10;chinaHourMinute(now) === config.sendTime严格相等判定 —— 一天只有这一分钟有机会,失败后当天彻底不推。群里一整天没消息,也没人知道任务其实跑过。
改动范围
只动
backend/src/jobs/warehouseLogisticsExceptionNotifyJob.js与对应单测。无接口变更、无表结构变更、无前端改动、无新依赖。
resolveScheduledPushDecision({ now, sendTime, state }),tick 每分钟问它一次,返回:before_time/already_sent_today/window_closed/wait_interval/first_round/retry。sendTime ~ sendTime + 30 分钟,窗口内每 5 分钟重试一次,成功即停(
lastSentDate落库后后续 tick 走already_sent_today)。attemptDate/attemptCount/lastAttemptAt:既做节流(避免每分钟重跑一次 240s 的全量核验),也做跨天归零。
sendTime + window超过 23:59 截到当天最后一分钟)—— 否则pushDate换天会把去重键带歪,同一天可能推两遍。
WLE_NOTIFY_RETRY_WINDOW_MINUTES(默认 30)、WLE_NOTIFY_RETRY_INTERVAL_MINUTES(默认 5)环境变量覆盖,现网调整不用发版。同步与兼容性
attemptDate !== pushDate即视为首轮,行为与改造前一致,不需要迁移。sendTime,业务侧无感知;页面「立即推送」走force分支,不受影响。验证
node --test backend/test/warehouseLogisticsExceptionNotify.test.js→ 30 / 30 通过(新增 10 条:到点首轮 / 未到点 / 已推过 / 间隔内节流 / 间隔到点 / 窗口边界含端点 /
窗口关闭 / 跨天归零 / 窗口不跨日 / 状态残缺不卡死 /
sendTime非法)node --check backend/src/jobs/warehouseLogisticsExceptionNotifyJob.js通过。2026-11-11T01:10:00Z= 北京 09:10),不依赖本机时区。风险与回退
秒失败、不会堆叠;
tickRunning互斥也保证同一时刻只有一轮。WLE_NOTIFY_RETRY_WINDOW_MINUTES=1即退回「只试一分钟」的旧行为,无需回滚代码。