Browse Source

task moniter ready

master
filesite 1 year ago
parent
commit
e80479b1e1
  1. 41
      lib/taskMoniter.mjs

41
lib/taskMoniter.mjs

@ -39,16 +39,50 @@ class TaskMoniter {
return this.taskStatus; 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;
}
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;
}
setTaskDone(task_id) {
if (typeof(this.tasks[task_id]) == 'undefined') {
return false;
} }
async setTaskDone(task) { this.tasks[task_id].status = this.statusCode.done;
this.taskStatus[this.statusCode.done] ++;
return true;
} }
async setTaskFailed(task) { 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) { async parseTaskFile(filename, filepath) {
@ -77,7 +111,6 @@ class TaskMoniter {
this.tasks[task.id] = task; this.tasks[task.id] = task;
this.taskStatus[task.status] ++; this.taskStatus[task.status] ++;
this.taskStatus.total ++; this.taskStatus.total ++;
//console.log('Task added', task);
return true; return true;
} }

Loading…
Cancel
Save