mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-24 21:04:33 +02:00
Update:Remove node-cron dependency
This commit is contained in:
parent
26ef275ab4
commit
b7e546f2f5
19 changed files with 686 additions and 18 deletions
34
server/libs/nodeCron/task.js
Normal file
34
server/libs/nodeCron/task.js
Normal 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;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue