Add @execute support to event scheduler

This commit is contained in:
Bryan Ashby 2016-06-20 18:58:54 -06:00
parent 3a41d550b0
commit 1e5a8da1e8
1 changed files with 21 additions and 3 deletions

View File

@ -9,6 +9,7 @@ const Log = require('./logger.js').log;
const _ = require('lodash'); const _ = require('lodash');
const later = require('later'); const later = require('later');
const path = require('path'); const path = require('path');
const pty = require('ptyw.js');
exports.getModule = EventSchedulerModule; exports.getModule = EventSchedulerModule;
exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart
@ -102,7 +103,7 @@ class ScheduledEvent {
} }
executeAction(cb) { executeAction(cb) {
Log.info( { eventName : this.name, action : this.action }, 'Executing scheduled action...'); Log.info( { eventName : this.name, action : this.action }, 'Executing scheduled event action...');
if('method' === this.action.type) { if('method' === this.action.type) {
const modulePath = path.join(__dirname, '../', this.action.location); // enigma-bbs base + supplied location (path/file.js') const modulePath = path.join(__dirname, '../', this.action.location); // enigma-bbs base + supplied location (path/file.js')
@ -112,7 +113,7 @@ class ScheduledEvent {
if(err) { if(err) {
Log.debug( Log.debug(
{ error : err.toString(), eventName : this.name, action : this.action }, { error : err.toString(), eventName : this.name, action : this.action },
'Error while performing scheduled event action'); 'Error performing scheduled event action');
} }
return cb(err); return cb(err);
@ -125,7 +126,24 @@ class ScheduledEvent {
return cb(e); return cb(e);
} }
} else if('execute' === this.action.type) { } else if('execute' === this.action.type) {
// :TODO: implement execute! const opts = {
// :TODO: cwd
name : this.name,
cols : 80,
rows : 24,
env : process.env,
};
const proc = pty.spawn(this.action.what, this.action.args, opts);
proc.once('exit', exitCode => {
if(exitCode) {
Log.warn(
{ eventName : this.name, action : this.action, exitCode : exitCode },
'Bad exit code while performing scheduled event action');
}
return cb(exitCode ? new Error(`Bad exit code while performing scheduled event action: ${exitCode}`) : null);
});
} }
} }
} }