fix(判题): 任务被遗弃时给提交落一个终态,别永远停在「等待评分」
judgeSubmission 自己的 try/catch 已经把正常路径上的异常都接住、落成 SYSTEM_ERROR 了,但队列的 failed 事件只有一行 console.error。判题队列没配 attempts(flowchart 队列配了 3),失败即终局;worker 进程被杀那种 —— 机房断电、容器 OOM、部署重启 —— BullMQ 走完 stalled 重入队还是没人接,最后 emit failed,那条提交就永远停在 「等待评分」:学生看着转圈,教师统计里还占着一个「判题中」的名额。 加 failAbandonedSubmission(),在 failed 里调用,复用已有的 markSystemError(只动 PENDING/JUDGING,判完的和重判过的都不会被覆盖)。三种情况实跑验过:不存在的提交 安全返回、卡住的那条变成 result=5 并写入 err_info、已 AC 的那条没被动。 生产库里 3 条卡死的 PENDING(2022-11 / 2026-03 / 2026-04)都是旧栈时代留下的, OJ2 上没有实例 —— 这次是把口子堵上,不是修已发生的故障。那 3 行和跟着差 1 的三道题 计数器还得手工处理。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KqjE6qPo67fqVDKn6Bx7yd
This commit is contained in:
@@ -2,7 +2,7 @@ import { Worker } from "bullmq"
|
||||
|
||||
import { config } from "./config"
|
||||
import { judgeQueueName, type JudgeJobData } from "./judge/job"
|
||||
import { judgeSubmission } from "./judge/run"
|
||||
import { failAbandonedSubmission, judgeSubmission } from "./judge/run"
|
||||
import { flowchartQueueName, type FlowchartJobData } from "./flowchart/job"
|
||||
import { evaluateFlowchart } from "./flowchart/run"
|
||||
import { createBlockingRedis } from "./redis"
|
||||
@@ -29,8 +29,17 @@ const flowchartWorker = new Worker<FlowchartJobData>(
|
||||
worker.on("ready", () => {
|
||||
console.log(`Judge worker ready (concurrency=${config.judgeConcurrency})`)
|
||||
})
|
||||
worker.on("failed", (job, error) => {
|
||||
worker.on("failed", async (job, error) => {
|
||||
console.error(`Judge job ${job?.id ?? "unknown"} failed`, error)
|
||||
// 队列没配 attempts,失败即终局;worker 被杀掉那种 BullMQ 走完 stalled 重试也会
|
||||
// 落到这里。不在这里写一个终态,提交就永远停在「等待评分」,没有任何人会再管它。
|
||||
const submissionId = job?.data.submissionId
|
||||
if (!submissionId) return
|
||||
try {
|
||||
await failAbandonedSubmission(submissionId, error)
|
||||
} catch (markError) {
|
||||
console.error(`Failed to mark submission ${submissionId} as system error`, markError)
|
||||
}
|
||||
})
|
||||
worker.on("error", (error) => {
|
||||
console.error("Judge worker error", error)
|
||||
|
||||
Reference in New Issue
Block a user