clonflict for silent

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

View File

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

View File

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

View File

@ -336,7 +336,15 @@ class Embark {
}
checkFn.fn(function (serviceCheckResult) {
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();
});

View File

@ -3,6 +3,8 @@ let utils = require('../../utils/utils.js');
let fs = require('../../core/fs.js');
let RunCode = require('../../coderunner/runCode');
let IpfsApi = require('ipfs-api');
const ProcessLauncher = require('../../process/ProcessLauncher');
const constants = require('../../constants');
class IPFS {
@ -15,6 +17,7 @@ class IPFS {
this.port = options.port || this.storageConfig.port;
this.addCheck = options.addCheck;
this.embark = embark;
this.ipfsProcess = null;
this.commandlineDeploy();
this.setServiceCheck();
@ -33,6 +36,30 @@ class 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() {
let self = this;
@ -58,7 +85,7 @@ class IPFS {
}
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) {
if (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({
modulePath: utils.joinPath(__dirname, 'webpackProcess.js'),
logger: self.logger,
events: self.events,
normalizeInput: utils.normalizeInput
events: self.events
});
webpackProcess.send({action: constants.pipeline.init, options: {}});
webpackProcess.send({action: constants.pipeline.build, file, importsList});

View File

@ -1,6 +1,7 @@
const child_process = require('child_process');
const constants = require('../constants');
const path = require('path');
const utils = require('../utils/utils');
class ProcessLauncher {
@ -9,7 +10,6 @@ class ProcessLauncher {
* @param {Object} options Options tp start the process
* * modulePath {String} Absolute path to the module to fork
* * logger {Object} Logger
* * normalizeInput {Function} Function to normalize logs
* * events {Function} Events Emitter instance
* @return {ProcessLauncher} The ProcessLauncher instance
*/
@ -17,7 +17,6 @@ class ProcessLauncher {
this.name = path.basename(options.modulePath);
this.process = child_process.fork(options.modulePath);
this.logger = options.logger;
this.normalizeInput = options.normalizeInput;
this.events = options.events;
this.silent = options.silent;
this.exitCallback = options.exitCallback;
@ -55,9 +54,9 @@ class ProcessLauncher {
return;
}
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

View File

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