2018-07-19 20:31:28 +00:00
|
|
|
|
|
|
|
class ProcessManager {
|
|
|
|
constructor(options) {
|
|
|
|
const self = this;
|
|
|
|
this.logger = options.logger;
|
|
|
|
this.events = options.events;
|
|
|
|
this.plugins = options.plugins;
|
|
|
|
this.processes = {};
|
|
|
|
|
|
|
|
self.events.setCommandHandler('processes:register', (name, cb) => {
|
|
|
|
this.processes[name] = {
|
|
|
|
state: 'unstarted',
|
|
|
|
cb: cb
|
2018-07-26 16:37:33 +00:00
|
|
|
};
|
2018-07-19 20:31:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
self.events.setCommandHandler('processes:launch', (name, cb) => {
|
|
|
|
let process = self.processes[name];
|
2018-07-27 21:33:50 +00:00
|
|
|
if (process.state !== 'unstarted') {
|
2018-07-19 20:31:28 +00:00
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
process.state = 'starting';
|
2018-07-26 16:37:33 +00:00
|
|
|
process.cb.apply(process.cb, [
|
|
|
|
() => {
|
|
|
|
process.state = 'running';
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
]);
|
2018-07-19 20:31:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ProcessManager;
|