audiobookshelf/server/libs/nodeCron/background-scheduled-task/daemon.js

20 lines
506 B
JavaScript
Raw Normal View History

2022-06-08 03:04:51 +02:00
const ScheduledTask = require('../scheduled-task');
let scheduledTask;
function register(message){
const script = require(message.path);
scheduledTask = new ScheduledTask(message.cron, script.task, message.options);
scheduledTask.on('task-done', (result) => {
process.send({ type: 'task-done', result});
});
process.send({ type: 'registred' });
}
process.on('message', (message) => {
switch(message.type){
case 'register':
return register(message);
}
});