Update:Remove node-cron dependency

This commit is contained in:
advplyr 2022-06-07 20:04:51 -05:00
parent 26ef275ab4
commit b7e546f2f5
19 changed files with 686 additions and 18 deletions

View file

@ -0,0 +1,34 @@
'use strict';
const EventEmitter = require('events');
class Task extends EventEmitter{
constructor(execution){
super();
if(typeof execution !== 'function') {
throw 'execution must be a function';
}
this._execution = execution;
}
execute(now) {
let exec;
try {
exec = this._execution(now);
} catch (error) {
return this.emit('task-failed', error);
}
if (exec instanceof Promise) {
return exec
.then(() => this.emit('task-finished'))
.catch((error) => this.emit('task-failed', error));
} else {
this.emit('task-finished');
return exec;
}
}
}
module.exports = Task;