Ai_GirlFriend/xuniYou/修复卡住的任务.sql
2026-03-02 18:57:11 +08:00

55 lines
1.2 KiB
SQL
Raw 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.

-- 修复卡住的任务将长时间running的任务标记为失败
-- 查看将要修复的任务
SELECT
id,
user_id,
task_type,
status,
created_at,
updated_at,
TIMESTAMPDIFF(MINUTE, updated_at, NOW()) as stuck_minutes,
JSON_EXTRACT(payload, '$.song_title') as song_title
FROM nf_generation_tasks
WHERE status = 'running'
AND TIMESTAMPDIFF(MINUTE, updated_at, NOW()) > 10
ORDER BY id;
-- 确认后执行以下语句修复
-- 方案1: 标记为失败(推荐)
UPDATE nf_generation_tasks
SET
status = 'failed',
error_msg = '任务处理超时,已自动标记为失败',
updated_at = NOW()
WHERE status = 'running'
AND TIMESTAMPDIFF(MINUTE, updated_at, NOW()) > 10;
-- 查看修复结果
SELECT
id,
status,
error_msg,
updated_at
FROM nf_generation_tasks
WHERE id IN (
SELECT id FROM (
SELECT id FROM nf_generation_tasks
WHERE error_msg LIKE '%超时%'
ORDER BY id DESC
LIMIT 10
) as tmp
);
-- 方案2: 重置为pending状态让系统重试
/*
UPDATE nf_generation_tasks
SET
status = 'pending',
error_msg = NULL,
updated_at = NOW()
WHERE status = 'running'
AND TIMESTAMPDIFF(MINUTE, updated_at, NOW()) > 10;
*/