clonflict for silent

This commit is contained in:
Jonathan Rainville 2018-05-28 11:48:27 -04:00
parent 8fa325a7af
commit b08190242b
8 changed files with 80 additions and 10 deletions

View File

@ -17,6 +17,8 @@
"contractConfigChanged": "contractConfigChanged" "contractConfigChanged": "contractConfigChanged"
}, },
"process": { "process": {
"processLaunchRequest": "process:launch-request",
"processLaunchComplete": "process:launch-complete",
"log": "log", "log": "log",
"events": { "events": {
"on": "on", "on": "on",

View File

@ -22,6 +22,7 @@ var Plugin = function(options) {
this.serviceChecks = []; this.serviceChecks = [];
this.pluginTypes = []; this.pluginTypes = [];
this.uploadCmds = []; this.uploadCmds = [];
this.processLaunchCmds = [];
this.imports = []; this.imports = [];
this.embarkjs_code = []; this.embarkjs_code = [];
this.embarkjs_init_code = {}; this.embarkjs_init_code = {};
@ -189,6 +190,11 @@ Plugin.prototype.registerUploadCommand = function(cmd, cb) {
this.pluginTypes.push('uploadCmds'); this.pluginTypes.push('uploadCmds');
}; };
Plugin.prototype.registerProcessLaunchCommand = function(cmd, cb) {
this.processLaunchCmds.push({cmd: cmd, cb: cb});
this.pluginTypes.push('processLaunchCmds');
};
Plugin.prototype.addCodeToEmbarkJS = function(code) { Plugin.prototype.addCodeToEmbarkJS = function(code) {
this.embarkjs_code.push(code); this.embarkjs_code.push(code);
this.pluginTypes.push('embarkjsCode'); this.pluginTypes.push('embarkjsCode');

View File

@ -324,7 +324,7 @@ class Embark {
callback(); callback();
}, },
function checkStorageService(callback){ function checkStorageService(callback){
let checkFn; let checkFn;
_.find(engine.servicesMonitor.checkList, (value, key) => { _.find(engine.servicesMonitor.checkList, (value, key) => {
if(key.toLowerCase() === platform.toLowerCase()){ if(key.toLowerCase() === platform.toLowerCase()){
checkFn = value; checkFn = value;
@ -336,7 +336,15 @@ class Embark {
} }
checkFn.fn(function (serviceCheckResult) { checkFn.fn(function (serviceCheckResult) {
if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { if (!serviceCheckResult.status || serviceCheckResult.status === 'off') {
return callback({message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})}); engine.events.emit(constants.process.processLaunchRequest, platform.toLowerCase());
engine.events.on(constants.process.processLaunchComplete, (processName) => {
if (platform.toLowerCase() !== processName) {
return;
}
console.log('GOT STUFF');
callback();
});
//return callback({message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})});
} }
callback(); callback();
}); });

View File

@ -3,6 +3,8 @@ let utils = require('../../utils/utils.js');
let fs = require('../../core/fs.js'); let fs = require('../../core/fs.js');
let RunCode = require('../../coderunner/runCode'); let RunCode = require('../../coderunner/runCode');
let IpfsApi = require('ipfs-api'); let IpfsApi = require('ipfs-api');
const ProcessLauncher = require('../../process/ProcessLauncher');
const constants = require('../../constants');
class IPFS { class IPFS {
@ -15,6 +17,7 @@ class IPFS {
this.port = options.port || this.storageConfig.port; this.port = options.port || this.storageConfig.port;
this.addCheck = options.addCheck; this.addCheck = options.addCheck;
this.embark = embark; this.embark = embark;
this.ipfsProcess = null;
this.commandlineDeploy(); this.commandlineDeploy();
this.setServiceCheck(); this.setServiceCheck();
@ -33,6 +36,30 @@ class IPFS {
this.embark.registerUploadCommand('ipfs', upload_ipfs.deploy.bind(upload_ipfs)); this.embark.registerUploadCommand('ipfs', upload_ipfs.deploy.bind(upload_ipfs));
} }
processExited(code) {
this.logger.error('IPFS process ended before the end of this process. Code: ' + code);
}
watchForProcessLaunch() {
const self = this;
self.events.on(constants.process.processLaunchRequest, (processName) => {
if (processName !== 'ipfs' || self.ipfsProcess) {
return;
}
self.ipfsProcess = new ProcessLauncher({
modulePath: utils.joinPath(__dirname, './ipfsProcess.js'),
logger: self.logger,
events: self.events,
silent: true,
exitCallback: self.processExited.bind(this)
});
self.ipfsProcess.send({action: constants.blockchain.init, options: {}});
self.events.emit(constants.process.processLaunchComplete, 'ipfs');
});
}
setServiceCheck() { setServiceCheck() {
let self = this; let self = this;
@ -58,7 +85,7 @@ class IPFS {
} }
self.addCheck('IPFS', function (cb) { self.addCheck('IPFS', function (cb) {
self.logger.trace("Checking IPFS version..."); self.logger.info("Checking IPFS version...");
utils.httpGetJson('http://' + self.host + ':' + self.port + '/api/v0/version', function (err, body) { utils.httpGetJson('http://' + self.host + ':' + self.port + '/api/v0/version', function (err, body) {
if (err) { if (err) {
self.logger.trace("Check IPFS version error: " + err); self.logger.trace("Check IPFS version error: " + err);

View File

@ -0,0 +1,30 @@
const shelljs = require('shelljs');
const ProcessWrapper = require('../../process/processWrapper');
const constants = require('../../constants');
let ipfsProcess;
class IPFSProcess extends ProcessWrapper {
constructor(_options) {
super();
this.startIPFSDaemon();
}
startIPFSDaemon() {
shelljs.exec('ipfs daemon', (err, _stdout, _stderr) => {
if (err) {
console.error(err);
process.exit(1);
}
process.exit();
});
}
}
process.on('message', (msg) => {
if (msg.action === constants.blockchain.init) {
ipfsProcess = new IPFSProcess(msg.options);
return ipfsProcess.send({result: constants.blockchain.initiated});
}
});

View File

@ -101,8 +101,7 @@ class Pipeline {
const webpackProcess = new ProcessLauncher({ const webpackProcess = new ProcessLauncher({
modulePath: utils.joinPath(__dirname, 'webpackProcess.js'), modulePath: utils.joinPath(__dirname, 'webpackProcess.js'),
logger: self.logger, logger: self.logger,
events: self.events, events: self.events
normalizeInput: utils.normalizeInput
}); });
webpackProcess.send({action: constants.pipeline.init, options: {}}); webpackProcess.send({action: constants.pipeline.init, options: {}});
webpackProcess.send({action: constants.pipeline.build, file, importsList}); webpackProcess.send({action: constants.pipeline.build, file, importsList});

View File

@ -1,6 +1,7 @@
const child_process = require('child_process'); const child_process = require('child_process');
const constants = require('../constants'); const constants = require('../constants');
const path = require('path'); const path = require('path');
const utils = require('../utils/utils');
class ProcessLauncher { class ProcessLauncher {
@ -9,7 +10,6 @@ class ProcessLauncher {
* @param {Object} options Options tp start the process * @param {Object} options Options tp start the process
* * modulePath {String} Absolute path to the module to fork * * modulePath {String} Absolute path to the module to fork
* * logger {Object} Logger * * logger {Object} Logger
* * normalizeInput {Function} Function to normalize logs
* * events {Function} Events Emitter instance * * events {Function} Events Emitter instance
* @return {ProcessLauncher} The ProcessLauncher instance * @return {ProcessLauncher} The ProcessLauncher instance
*/ */
@ -17,7 +17,6 @@ class ProcessLauncher {
this.name = path.basename(options.modulePath); this.name = path.basename(options.modulePath);
this.process = child_process.fork(options.modulePath); this.process = child_process.fork(options.modulePath);
this.logger = options.logger; this.logger = options.logger;
this.normalizeInput = options.normalizeInput;
this.events = options.events; this.events = options.events;
this.silent = options.silent; this.silent = options.silent;
this.exitCallback = options.exitCallback; this.exitCallback = options.exitCallback;
@ -55,9 +54,9 @@ class ProcessLauncher {
return; return;
} }
if (this.logger[msg.type]) { if (this.logger[msg.type]) {
return this.logger[msg.type](this.normalizeInput(msg.message)); return this.logger[msg.type](utils.normalizeInput(msg.message));
} }
this.logger.debug(this.normalizeInput(msg.message)); this.logger.debug(utils.normalizeInput(msg.message));
} }
// Handle event calls from the child process // Handle event calls from the child process

View File

@ -24,7 +24,6 @@ class BlockchainProcessLauncher {
modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'), modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'),
logger: this.logger, logger: this.logger,
events: this.events, events: this.events,
normalizeInput: this.normalizeInput,
silent: this.logger.logLevel !== 'trace', silent: this.logger.logLevel !== 'trace',
exitCallback: this.processEnded.bind(this) exitCallback: this.processEnded.bind(this)
}); });