worker.exitedAfterDisconnect
如果工作进程由于 .kill()
或 .disconnect()
退出,则此属性为 true
。
如果工作进程以任何其他方式退出,则为 false
。
如果工作进程没有退出,则为 undefined
。
布尔值 worker.exitedAfterDisconnect
可以区分自愿退出和意外退出,主进程可以根据此值选择不重新衍生工作进程。
cluster.on('exit', (worker, code, signal) => {
if (worker.exitedAfterDisconnect === true) {
console.log('Oh, it was just voluntary – no need to worry');
}
});
// 杀死工作进程
worker.kill();
This property is true
if the worker exited due to .kill()
or
.disconnect()
. If the worker exited any other way, it is false
. If the
worker has not exited, it is undefined
.
The boolean worker.exitedAfterDisconnect
allows distinguishing between
voluntary and accidental exit, the master may choose not to respawn a worker
based on this value.
cluster.on('exit', (worker, code, signal) => {
if (worker.exitedAfterDisconnect === true) {
console.log('Oh, it was just voluntary – no need to worry');
}
});
// kill worker
worker.kill();