From 688a39b8bc5724f06c69eed49224da4123f181b8 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 23 May 2018 11:06:58 -0400 Subject: [PATCH] show message when process doesnt end with code 0 --- lib/process/processLauncher.js | 11 +++++++++-- lib/processes/blockchainProcessLauncher.js | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/process/processLauncher.js b/lib/process/processLauncher.js index 15a9f95a..450a3600 100644 --- a/lib/process/processLauncher.js +++ b/lib/process/processLauncher.js @@ -1,6 +1,6 @@ const child_process = require('child_process'); const constants = require('../constants'); - +const path = require('path'); class ProcessLauncher { @@ -14,11 +14,13 @@ class ProcessLauncher { * @return {ProcessLauncher} The ProcessLauncher instance */ constructor(options) { + 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; this.subscriptions = {}; this._subscribeToMessages(); @@ -38,7 +40,12 @@ class ProcessLauncher { }); this.process.on('exit', (code) => { - self.logger.info('Process exited with code ' + code); + if (self.exitCallback) { + return self.exitCallback(code); + } + if (code) { + this.logger.info(`Child Process ${this.name} exited with code ${code}`); + } }); } diff --git a/lib/processes/blockchainProcessLauncher.js b/lib/processes/blockchainProcessLauncher.js index 9b089d76..7cf79711 100644 --- a/lib/processes/blockchainProcessLauncher.js +++ b/lib/processes/blockchainProcessLauncher.js @@ -12,6 +12,10 @@ class BlockchainProcessLauncher { this.locale = options.locale; } + processEnded(code) { + this.logger.error('Blockchain process ended before the end of this process. Code: ' + code); + } + startBlockchainNode() { this.logger.info('Starting Blockchain node in another process'.cyan); @@ -20,7 +24,8 @@ class BlockchainProcessLauncher { logger: this.logger, events: this.events, normalizeInput: this.normalizeInput, - silent: true + silent: true, + exitCallback: this.processEnded.bind(this) }); this.blockchainProcess.send({ action: constants.blockchain.init, options: {