Browse Source

add checking detect

master
filesite 1 year ago
parent
commit
a0ab271a40
  1. 21
      lib/taskMoniter.mjs

21
lib/taskMoniter.mjs

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

Loading…
Cancel
Save