attempt to clear up server dev server messaging
This commit is contained in:
parent
9874366e4b
commit
3bbf036b29
|
@ -112,7 +112,7 @@ module.exports = class ClusterManager {
|
|||
}
|
||||
|
||||
onWatcherError(err) {
|
||||
this.log.bad('Failed to watch files!\n', err.stack);
|
||||
this.log.bad('failed to watch files!\n', err.stack);
|
||||
process.exit(1); // eslint-disable-line no-process-exit
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,6 +14,15 @@ cluster.setupMaster({
|
|||
silent: false
|
||||
});
|
||||
|
||||
let dead = fork => {
|
||||
return fork.isDead() || fork.killed;
|
||||
};
|
||||
|
||||
let kill = fork => {
|
||||
fork.kill('SIGINT'); // make it snappy
|
||||
fork.killed = true;
|
||||
};
|
||||
|
||||
module.exports = class Worker extends EventEmitter {
|
||||
constructor(opts) {
|
||||
opts = opts || {};
|
||||
|
@ -23,6 +32,7 @@ module.exports = class Worker extends EventEmitter {
|
|||
this.type = opts.type;
|
||||
this.title = opts.title || opts.type;
|
||||
this.watch = (opts.watch !== false);
|
||||
this.startCount = 0;
|
||||
this.online = false;
|
||||
this.changes = [];
|
||||
|
||||
|
@ -47,6 +57,7 @@ module.exports = class Worker extends EventEmitter {
|
|||
|
||||
if (code) {
|
||||
this.log.bad(`${this.title} crashed`, 'with status code', code);
|
||||
if (!this.watch) process.exit(code);
|
||||
} else {
|
||||
// restart after graceful shutdowns
|
||||
this.start();
|
||||
|
@ -60,8 +71,8 @@ module.exports = class Worker extends EventEmitter {
|
|||
}
|
||||
|
||||
shutdown() {
|
||||
if (this.fork && !this.fork.isDead()) {
|
||||
this.fork.kill();
|
||||
if (this.fork && !dead(this.fork)) {
|
||||
kill(this.fork);
|
||||
this.fork.removeListener('message', this.onMessage);
|
||||
this.fork.removeListener('online', this.onOnline);
|
||||
this.fork.removeListener('disconnect', this.onDisconnect);
|
||||
|
@ -90,15 +101,14 @@ module.exports = class Worker extends EventEmitter {
|
|||
}
|
||||
|
||||
start() {
|
||||
if (this.fork && !this.fork.isDead()) {
|
||||
// once "exit" event is received with 0 status, start() is called again
|
||||
return this.shutdown();
|
||||
}
|
||||
// once "exit" event is received with 0 status, start() is called again
|
||||
if (this.fork) return this.shutdown();
|
||||
|
||||
if (this.fork && this.changes.length) {
|
||||
this.log.warn(`${this.title} restarting`, `due to changes in ${this.flushChangeBuffer()}`);
|
||||
} else {
|
||||
this.log.warn(`${this.title} starting`);
|
||||
if (this.changes.length) {
|
||||
this.log.warn(`restarting ${this.title}`, `due to changes in ${this.flushChangeBuffer()}`);
|
||||
}
|
||||
else if (this.startCount++) {
|
||||
this.log.warn(`restarting ${this.title}...`);
|
||||
}
|
||||
|
||||
this.fork = cluster.fork(this.env);
|
||||
|
|
|
@ -19,14 +19,23 @@ module.exports = async (kbnServer, kibanaHapiServer, config) => {
|
|||
})
|
||||
);
|
||||
|
||||
await server.init();
|
||||
|
||||
let ready = false;
|
||||
|
||||
let sendReady = () => {
|
||||
process.send(['WORKER_BROADCAST', { optimizeReady: true }]);
|
||||
if (!process.connected) return;
|
||||
process.send(['WORKER_BROADCAST', { optimizeReady: ready }]);
|
||||
};
|
||||
|
||||
sendReady();
|
||||
process.on('message', (msg) => {
|
||||
if (msg && msg.optimizeReady === '?') sendReady();
|
||||
});
|
||||
|
||||
|
||||
sendReady();
|
||||
|
||||
await server.init();
|
||||
|
||||
ready = true;
|
||||
sendReady();
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
let { fromNode } = require('bluebird');
|
||||
let { get } = require('lodash');
|
||||
let { get, once } = require('lodash');
|
||||
|
||||
module.exports = (kbnServer, server, config) => {
|
||||
|
||||
|
@ -21,11 +21,22 @@ module.exports = (kbnServer, server, config) => {
|
|||
cb(new Error('Server timedout waiting for the optimizer to become ready'));
|
||||
}, config.get('optimize.lazyProxyTimeout'));
|
||||
|
||||
let waiting = once(() => {
|
||||
server.log(['info', 'optimize'], 'Waiting for optimizer completion');
|
||||
});
|
||||
|
||||
if (!process.connected) return;
|
||||
|
||||
process.send(['WORKER_BROADCAST', { optimizeReady: '?' }]);
|
||||
process.on('message', (msg) => {
|
||||
if (get(msg, 'optimizeReady')) {
|
||||
clearTimeout(timeout);
|
||||
cb();
|
||||
switch (get(msg, 'optimizeReady')) {
|
||||
case true:
|
||||
clearTimeout(timeout);
|
||||
cb();
|
||||
break;
|
||||
case false:
|
||||
waiting();
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue