|
|
@ -14,6 +14,8 @@ class TaskMoniter { |
|
|
|
|
|
|
|
|
|
|
|
constructor(task_list_dir) { |
|
|
|
constructor(task_list_dir) { |
|
|
|
this.check_time_gap = 10; //检测间隔时间,单位:秒
|
|
|
|
this.check_time_gap = 10; //检测间隔时间,单位:秒
|
|
|
|
|
|
|
|
this.checking = false; |
|
|
|
|
|
|
|
|
|
|
|
this.task_dir = task_list_dir; //监控目录:任务列表保存目录
|
|
|
|
this.task_dir = task_list_dir; //监控目录:任务列表保存目录
|
|
|
|
this.tasks = {}; //内存中的任务列表
|
|
|
|
this.tasks = {}; //内存中的任务列表
|
|
|
|
this.taskStatus = { //当前任务状态
|
|
|
|
this.taskStatus = { //当前任务状态
|
|
|
@ -42,16 +44,31 @@ class TaskMoniter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async checkTasks() { |
|
|
|
async checkTasks() { |
|
|
|
|
|
|
|
if (this.checking == true) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
this.checking = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//do something
|
|
|
|
|
|
|
|
console.log('[%s] TaskMoniter auto check...', common.getTimeString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.checking = false; |
|
|
|
|
|
|
|
}catch(error) { |
|
|
|
|
|
|
|
this.checking = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
run() { //开始监控任务目录,把所有任务缓存到内存
|
|
|
|
run() { //开始监控任务目录,把所有任务缓存到内存
|
|
|
|
console.log('[%s] TaskMoniter started.', common.getTimeString()); |
|
|
|
console.log('[%s] TaskMoniter started.', common.getTimeString()); |
|
|
|
|
|
|
|
|
|
|
|
//auto run
|
|
|
|
//auto run
|
|
|
|
|
|
|
|
const _self = this; |
|
|
|
const task_check_time = this.check_time_gap; |
|
|
|
const task_check_time = this.check_time_gap; |
|
|
|
const task_auto_run = cron.schedule(`*/${task_check_time} * * * * *`, () => { |
|
|
|
const task_auto_run = cron.schedule(`*/${task_check_time} * * * * *`, () => { |
|
|
|
console.log('[%s] TaskMoniter auto check...', common.getTimeString()); |
|
|
|
_self.checkTasks(); |
|
|
|
|
|
|
|
|
|
|
|
}, { |
|
|
|
}, { |
|
|
|
scheduled: false |
|
|
|
scheduled: false |
|
|
|
}); |
|
|
|
}); |
|
|
|