Files
biz-api-cloud-zax/db/20260914_slow_zombie_refund_tasks.sql
2026-09-14 22:07:48 +08:00

31 lines
1.4 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 2026-09-14 自动退款任务僵尸循环止血脚本
--
-- 背景:商户关闭自动退款开关的任务被置为 status='30'(开关关闭暂停)且 next_retry_time=NULL,
-- 扫描器对 next_retry_time IS NULL 的暂停任务每 30 秒无条件重扫,配合 wallet 配置服务不可达,
-- 形成 select for update + Feign 超时的死循环,拖垮订单接口(当晚 page-join 504)。
-- 代码修复(暂停任务加 10 分钟退避)上线后新数据自动退避,本脚本只处理存量 NULL 行。
--
-- 执行方式:手工执行(无自动迁移),先于代码部署。
-- 注意:不置终态——商户重新打开开关后任务仍可正常退款,仅把复查时间推迟一天降温。
-- 1. 执行前确认存量僵尸任务数量(预期为线上扫描风暴的规模)
SELECT COUNT(*) AS zombie_task_count
FROM hard_auto_refund_task
WHERE del_flag = '0'
AND status = '30'
AND next_retry_time IS NULL;
-- 2. 将存量僵尸任务的复查时间推至一天后,立即脱离 30 秒扫描循环
UPDATE hard_auto_refund_task
SET next_retry_time = DATE_ADD(NOW(), INTERVAL 1 DAY)
WHERE del_flag = '0'
AND status = '30'
AND next_retry_time IS NULL;
-- 3. 执行后确认已无 NULL 复查时间的暂停任务(预期为 0)
SELECT COUNT(*) AS remaining_zombie_task_count
FROM hard_auto_refund_task
WHERE del_flag = '0'
AND status = '30'
AND next_retry_time IS NULL;