From f03a296db6f18576920d9be41b79e8cb3d0e0bca Mon Sep 17 00:00:00 2001 From: filesite Date: Thu, 18 Apr 2024 10:58:34 +0800 Subject: [PATCH] improve task save fail and crap fail logic --- lib/taskMoniter.mjs | 16 ++++++++++++++-- spider.mjs | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/taskMoniter.mjs b/lib/taskMoniter.mjs index 65396dc..b1f8bf9 100644 --- a/lib/taskMoniter.mjs +++ b/lib/taskMoniter.mjs @@ -95,6 +95,18 @@ class TaskMoniter { return true; } + setTaskWaiting(task_id) { + if (typeof(this.tasks[task_id]) == 'undefined') { + return false; + } + + this.taskStatus[this.tasks[task_id].status] --; + this.taskStatus[this.statusCode.waiting] ++; + this.tasks[task_id].status = this.statusCode.waiting; + + return true; + } + setTaskDone(task_id) { if (typeof(this.tasks[task_id]) == 'undefined') { return false; @@ -243,8 +255,8 @@ class TaskMoniter { console.log("[%s][%s] Task %s's data save to HeroUnion done", common.getTimeString(), task.notify_time, task.id); }else { - console.log("[%s][%s] Task %s's data save to HeroUnion failed, it will try again later.", - common.getTimeString(), task.notify_time, task.id); + console.error("[%s][%s] Task %s's data save to HeroUnion failed, it will try again later. Error message: %s", + common.getTimeString(), task.notify_time, task.id, saveRes.message); } this.updateTask(task.id, task); //更新任务数据 diff --git a/spider.mjs b/spider.mjs index 9a9d1ff..af1a77e 100644 --- a/spider.mjs +++ b/spider.mjs @@ -109,6 +109,8 @@ import cron from 'node-cron'; //上报联盟,任务失败 heroBot.saveTaskData(task.id, task.token, [], 'failed'); + }else { + taskMoniter.setTaskWaiting(task.id); //重新进入等待处理状态 } }