close workers on process exit
This commit is contained in:
parent
c7b441f6d5
commit
f863b30792
|
@ -33,10 +33,11 @@ module.exports = class Worker extends EventEmitter {
|
|||
kbnWorkerArgv: JSON.stringify(argv)
|
||||
};
|
||||
|
||||
_.bindAll(this, ['onExit', 'onMessage', 'start']);
|
||||
_.bindAll(this, ['onExit', 'onMessage', 'onShutdown', 'start']);
|
||||
|
||||
this.start = _.debounce(this.start, 25);
|
||||
cluster.on('exit', this.onExit);
|
||||
process.on('exit', this.onShutdown);
|
||||
}
|
||||
|
||||
onExit(fork, code) {
|
||||
|
@ -51,6 +52,12 @@ module.exports = class Worker extends EventEmitter {
|
|||
this.start();
|
||||
}
|
||||
|
||||
onShutdown() {
|
||||
if (this.fork && !this.fork.isDead()) {
|
||||
this.fork.kill();
|
||||
}
|
||||
}
|
||||
|
||||
onMessage(msg) {
|
||||
if (!_.isArray(msg) || msg[0] !== 'WORKER_BROADCAST') return;
|
||||
this.emit('broadcast', msg[1]);
|
||||
|
|
Loading…
Reference in a new issue