move processes into core

This commit is contained in:
Iuri Matias 2018-07-27 17:33:50 -04:00 committed by Pascal Precht
parent ac4b74588e
commit 3a532a05e8
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
7 changed files with 16 additions and 76 deletions

View File

@ -42,9 +42,6 @@ class ProcessLauncher {
_subscribeToMessages() {
const self = this;
this.process.on('message', (msg) => {
if (msg.error) {
self.logger.error(msg.error);
}
if (msg.result === constants.process.log) {
return self._handleLog(msg);
}

View File

@ -1,7 +1,7 @@
const child_process = require('child_process');
const constants = require('../constants');
const constants = require('../../constants');
const path = require('path');
const utils = require('../utils/utils');
const utils = require('../../utils/utils');
class ProcessLauncher {
@ -29,6 +29,9 @@ class ProcessLauncher {
_subscribeToMessages() {
const self = this;
this.process.on('message', (msg) => {
if (msg.error) {
self.logger.error(msg.error);
}
if (msg.result === constants.process.log) {
return self._handleLog(msg);
}

View File

@ -16,7 +16,7 @@ class ProcessManager {
self.events.setCommandHandler('processes:launch', (name, cb) => {
let process = self.processes[name];
if (process.state !== 'unstarted') {
if (process.state != 'unstarted') {
return cb();
}
process.state = 'starting';

View File

@ -16,8 +16,7 @@ class ProcessManager {
self.events.setCommandHandler('processes:launch', (name, cb) => {
let process = self.processes[name];
if (process.state != 'unstarted') {
console.dir("=====> already started " + name);
if (process.state !== 'unstarted') {
return cb();
}
process.state = 'starting';

View File

@ -1,7 +1,3 @@
process.on('uncaughtException', function(e){
process.send({error: e.stack});
});
const constants = require('../../constants');
const Events = require('./eventsWrapper');

View File

@ -1,14 +1,14 @@
const constants = require('../constants');
process.on('uncaughtException', function(e){
process.send({error: e.stack});
});
const constants = require('../../constants');
const Events = require('./eventsWrapper');
// Override process.chdir so that we have a partial-implementation PWD for Windows
const realChdir = process.chdir;
process.chdir = (...args) => {
// Set PWD to CWD since Windows doesn't have a value for PWD
if (!process.env.PWD) {
process.env.PWD = process.cwd();
}
realChdir(...args);
};
class ProcessWrapper {

View File

@ -1,55 +0,0 @@
const uuid = require('uuid/v1');
const constants = require('../constants');
class Events {
/**
* Constructs an event wrapper for processes.
* Handles sending an event message to the parent process and waiting for its response
* No need to create an instance of eventsWrapper for your own process, just extend ProcessWrapper
* Then, you an use `this.events.[on|request]` with the usual parameters you would use
*/
constructor() {
this.subscribedEvents = {};
this.listenToParentProcess();
}
listenToParentProcess() {
process.on('message', (msg) => {
if (!msg.event || msg.event !== constants.process.events.response) {
return;
}
if (!this.subscribedEvents[msg.eventId]) {
return;
}
this.subscribedEvents[msg.eventId](msg.result);
});
}
sendEvent() {
const eventType = arguments[0];
const requestName = arguments[1];
let args = [].slice.call(arguments, 2);
const eventId = uuid();
this.subscribedEvents[eventId] = args[args.length - 1];
args = args.splice(0, args.length - 2);
process.send({
event: eventType,
requestName,
args,
eventId: eventId
});
}
on() {
this.sendEvent(constants.process.events.on, ...arguments);
}
request() {
this.sendEvent(constants.process.events.request, ...arguments);
}
}
module.exports = Events;