parent
81301047b3
commit
7eb7500ad8
|
@ -100,6 +100,34 @@ class ScheduledEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executeAction(cb) {
|
||||||
|
Log.info( { eventName : this.name, action : this.action }, 'Executing scheduled action...');
|
||||||
|
|
||||||
|
if('method' === this.action.type) {
|
||||||
|
const modulePath = path.join(__dirname, '../', this.action.location); // enigma-bbs base + supplied location (path/file.js')
|
||||||
|
try {
|
||||||
|
const methodModule = require(modulePath);
|
||||||
|
methodModule[this.action.what](this.action.args, err => {
|
||||||
|
if(err) {
|
||||||
|
Log.debug(
|
||||||
|
{ error : err.toString(), eventName : this.name, action : this.action },
|
||||||
|
'Error while performing scheduled event action');
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb(err);
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
Log.warn(
|
||||||
|
{ error : e.toString(), eventName : this.name, action : this.action },
|
||||||
|
'Failed to perform scheduled event action');
|
||||||
|
|
||||||
|
return cb(e);
|
||||||
|
}
|
||||||
|
} else if('execute' === this.action.type) {
|
||||||
|
// :TODO: implement execute!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function EventSchedulerModule(options) {
|
function EventSchedulerModule(options) {
|
||||||
|
@ -119,27 +147,9 @@ function EventSchedulerModule(options) {
|
||||||
|
|
||||||
self.runningActions.add(schedEvent.name);
|
self.runningActions.add(schedEvent.name);
|
||||||
|
|
||||||
if('method' === schedEvent.action.type) {
|
schedEvent.executeAction( () => {
|
||||||
const modulePath = path.join(__dirname, '../', schedEvent.action.location); // enigma-bbs base + supplied location (path/file.js')
|
|
||||||
try {
|
|
||||||
const methodModule = require(modulePath);
|
|
||||||
methodModule[schedEvent.action.what](schedEvent.action.args, err => {
|
|
||||||
if(err) {
|
|
||||||
Log.debug(
|
|
||||||
{ error : err.toString(), eventName : schedEvent.name, action : schedEvent.action },
|
|
||||||
'Error while performing scheduled event action');
|
|
||||||
}
|
|
||||||
|
|
||||||
self.runningActions.delete(schedEvent.name);
|
self.runningActions.delete(schedEvent.name);
|
||||||
});
|
});
|
||||||
} catch(e) {
|
|
||||||
Log.warn(
|
|
||||||
{ error : e.toString(), eventName : schedEvent.name, action : schedEvent.action },
|
|
||||||
'Failed to perform scheduled event action');
|
|
||||||
|
|
||||||
self.runningActions.delete(schedEvent.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +190,15 @@ EventSchedulerModule.prototype.startup = function(cb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.debug(
|
||||||
|
{
|
||||||
|
evetnName : schedEvent.name,
|
||||||
|
schedule : this.moduleConfig.events[schedEvent.name].schedule,
|
||||||
|
action : schedEvent.action,
|
||||||
|
},
|
||||||
|
'Scheduled event loaded'
|
||||||
|
);
|
||||||
|
|
||||||
if(schedEvent.schedule.sched) {
|
if(schedEvent.schedule.sched) {
|
||||||
this.eventTimers.push(later.setInterval( () => {
|
this.eventTimers.push(later.setInterval( () => {
|
||||||
self.performAction(schedEvent);
|
self.performAction(schedEvent);
|
||||||
|
|
Loading…
Reference in New Issue