From e80479b1e1fa274f3953ed357a9b377e6ea7b919 Mon Sep 17 00:00:00 2001 From: filesite Date: Fri, 15 Sep 2023 08:34:17 +0800 Subject: [PATCH] task moniter ready --- lib/taskMoniter.mjs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/taskMoniter.mjs b/lib/taskMoniter.mjs index 2f4619e..4fba55b 100644 --- a/lib/taskMoniter.mjs +++ b/lib/taskMoniter.mjs @@ -39,16 +39,50 @@ class TaskMoniter { return this.taskStatus; } - async getNewTask() { + getNewTask() { + let task = null; + for (const item of this.tasks) { + if (item.status == this.statusCode.waiting) { + task = item; + break; + } + } + + return task; } - async setTaskDone(task) { + setTaskRunning(task_id) { + if (typeof(this.tasks[task_id]) == 'undefined') { + return false; + } + + this.tasks[task_id].status = this.statusCode.running; + this.taskStatus[this.statusCode.running] ++; + return true; } - async setTaskFailed(task) { + setTaskDone(task_id) { + if (typeof(this.tasks[task_id]) == 'undefined') { + return false; + } + this.tasks[task_id].status = this.statusCode.done; + this.taskStatus[this.statusCode.done] ++; + + return true; + } + + setTaskFailed(task_id) { + if (typeof(this.tasks[task_id]) == 'undefined') { + return false; + } + + this.tasks[task_id].status = this.statusCode.failed; + this.taskStatus[this.statusCode.failed] ++; + + return true; } async parseTaskFile(filename, filepath) { @@ -77,7 +111,6 @@ class TaskMoniter { this.tasks[task.id] = task; this.taskStatus[task.status] ++; this.taskStatus.total ++; - //console.log('Task added', task); return true; }