Browse Source

delete task file when task is done

master
filesite 1 year ago
parent
commit
754d893e48
  1. 14
      lib/common.mjs
  2. 7
      lib/taskMoniter.mjs

14
lib/common.mjs

@ -1,4 +1,6 @@
//公用方法 //公用方法
import { rm as removeFile } from 'node:fs/promises';
export default { export default {
getTimeString: function(locales) { getTimeString: function(locales) {
@ -7,4 +9,16 @@ export default {
return today.toLocaleString(locales); return today.toLocaleString(locales);
}, },
removeFile: async function(filepath) {
let done = false;
try {
done = await removeFile(filepath, {force: true});
}catch(error) {
console.error('Remove task file failed: %s', error);
}
return done;
}
}; };

7
lib/taskMoniter.mjs

@ -35,6 +35,11 @@ class TaskMoniter {
}; };
} }
getTaskFilePath(task_id) {
const dirPath = path.resolve(this.task_dir);
return `${dirPath}/${task_id}.task`;
}
getStatus() { getStatus() {
return this.taskStatus; return this.taskStatus;
} }
@ -71,6 +76,8 @@ class TaskMoniter {
this.tasks[task_id].status = this.statusCode.done; this.tasks[task_id].status = this.statusCode.done;
this.taskStatus[this.statusCode.done] ++; this.taskStatus[this.statusCode.done] ++;
const filepath = this.getTaskFilePath(task_id);
common.removeFile(filepath); //async delete
return true; return true;
} }

Loading…
Cancel
Save