cluster: Rename 'death' back to 'exit'
This commit is contained in:
parent
407181538b
commit
90ce5b3d41
@ -19,7 +19,7 @@ all share server ports.
|
|||||||
cluster.fork();
|
cluster.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster.on('death', function(worker) {
|
cluster.on('exit', function(worker) {
|
||||||
console.log('worker ' + worker.pid + ' died');
|
console.log('worker ' + worker.pid + ' died');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -87,7 +87,7 @@ This can be used to log worker activity, and create you own timeout.
|
|||||||
cluster.on('listening', function (worker) {
|
cluster.on('listening', function (worker) {
|
||||||
clearTimeout(timeouts[worker.uniqueID]);
|
clearTimeout(timeouts[worker.uniqueID]);
|
||||||
});
|
});
|
||||||
cluster.on('death', function (worker) {
|
cluster.on('exit', function (worker) {
|
||||||
clearTimeout(timeouts[worker.uniqueID]);
|
clearTimeout(timeouts[worker.uniqueID]);
|
||||||
errorMsg();
|
errorMsg();
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ When a workers IPC channel has disconnected this event is emitted. This will hap
|
|||||||
when the worker dies, usually after calling `.destroy()`.
|
when the worker dies, usually after calling `.destroy()`.
|
||||||
|
|
||||||
When calling `.disconnect()`, there may be a delay between the
|
When calling `.disconnect()`, there may be a delay between the
|
||||||
`disconnect` and `death` events. This event can be used to detect if
|
`disconnect` and `exit` events. This event can be used to detect if
|
||||||
the process is stuck in a cleanup or if there are long-living
|
the process is stuck in a cleanup or if there are long-living
|
||||||
connections.
|
connections.
|
||||||
|
|
||||||
@ -134,14 +134,14 @@ connections.
|
|||||||
console.log('The worker #' + worker.uniqueID + ' has disconnected');
|
console.log('The worker #' + worker.uniqueID + ' has disconnected');
|
||||||
});
|
});
|
||||||
|
|
||||||
## Event: 'death'
|
## Event: 'exit'
|
||||||
|
|
||||||
* `worker` {Worker object}
|
* `worker` {Worker object}
|
||||||
|
|
||||||
When any of the workers die the cluster module will emit the 'death' event.
|
When any of the workers die the cluster module will emit the 'exit' event.
|
||||||
This can be used to restart the worker by calling `fork()` again.
|
This can be used to restart the worker by calling `fork()` again.
|
||||||
|
|
||||||
cluster.on('death', function(worker) {
|
cluster.on('exit', function(worker) {
|
||||||
console.log('worker ' + worker.pid + ' died. restart...');
|
console.log('worker ' + worker.pid + ' died. restart...');
|
||||||
cluster.fork();
|
cluster.fork();
|
||||||
});
|
});
|
||||||
@ -286,10 +286,10 @@ This example will echo back all messages from the master:
|
|||||||
### worker.destroy()
|
### worker.destroy()
|
||||||
|
|
||||||
This function will kill the worker, and inform the master to not spawn a
|
This function will kill the worker, and inform the master to not spawn a
|
||||||
new worker. To know the difference between suicide and accidentally death
|
new worker. To know the difference between suicide and accidentally
|
||||||
a suicide boolean is set to true.
|
exit, the `suicide` boolean is set to true.
|
||||||
|
|
||||||
cluster.on('death', function (worker) {
|
cluster.on('exit', function (worker) {
|
||||||
if (worker.suicide === true) {
|
if (worker.suicide === true) {
|
||||||
console.log('Oh, it was just suicide\' – no need to worry').
|
console.log('Oh, it was just suicide\' – no need to worry').
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ When calling this function the worker will no longer accept new connections, but
|
|||||||
they will be handled by any other listening worker. Existing connection will be
|
they will be handled by any other listening worker. Existing connection will be
|
||||||
allowed to exit as usual. When no more connections exist, the IPC channel to the worker
|
allowed to exit as usual. When no more connections exist, the IPC channel to the worker
|
||||||
will close allowing it to die graceful. When the IPC channel is closed the `disconnect`
|
will close allowing it to die graceful. When the IPC channel is closed the `disconnect`
|
||||||
event will emit, this is then followed by the `death` event, there is emitted when
|
event will emit, this is then followed by the `exit` event, there is emitted when
|
||||||
the worker finally die.
|
the worker finally die.
|
||||||
|
|
||||||
Because there might be long living connections, it is useful to implement a timeout.
|
Because there might be long living connections, it is useful to implement a timeout.
|
||||||
@ -427,13 +427,13 @@ on the specified worker.
|
|||||||
// Worker has disconnected
|
// Worker has disconnected
|
||||||
};
|
};
|
||||||
|
|
||||||
### Event: 'death'
|
### Event: 'exit'
|
||||||
|
|
||||||
* `worker` {Worker object}
|
* `worker` {Worker object}
|
||||||
|
|
||||||
Same as the `cluster.on('death')` event, but emits only when the state change
|
Same as the `cluster.on('exit')` event, but emits only when the state change
|
||||||
on the specified worker.
|
on the specified worker.
|
||||||
|
|
||||||
cluster.fork().on('death', function (worker) {
|
cluster.fork().on('exit', function (worker) {
|
||||||
// Worker has died
|
// Worker has died
|
||||||
};
|
};
|
||||||
|
@ -294,9 +294,9 @@ function Worker(customEnv) {
|
|||||||
|
|
||||||
// handle internalMessage, exit and disconnect event
|
// handle internalMessage, exit and disconnect event
|
||||||
this.process.on('internalMessage', handleMessage.bind(null, this));
|
this.process.on('internalMessage', handleMessage.bind(null, this));
|
||||||
this.process.on('exit', prepareDeath.bind(null, this, 'dead', 'death'));
|
this.process.on('exit', prepareExit.bind(null, this, 'dead', 'exit'));
|
||||||
this.process.on('disconnect',
|
this.process.on('disconnect',
|
||||||
prepareDeath.bind(null, this, 'disconnected', 'disconnect'));
|
prepareExit.bind(null, this, 'disconnected', 'disconnect'));
|
||||||
|
|
||||||
// relay message and error
|
// relay message and error
|
||||||
this.process.on('message', this.emit.bind(this, 'message'));
|
this.process.on('message', this.emit.bind(this, 'message'));
|
||||||
@ -306,7 +306,7 @@ function Worker(customEnv) {
|
|||||||
util.inherits(Worker, EventEmitter);
|
util.inherits(Worker, EventEmitter);
|
||||||
cluster.Worker = Worker;
|
cluster.Worker = Worker;
|
||||||
|
|
||||||
function prepareDeath(worker, state, eventName) {
|
function prepareExit(worker, state, eventName) {
|
||||||
|
|
||||||
// set state to disconnect
|
// set state to disconnect
|
||||||
worker.state = state;
|
worker.state = state;
|
||||||
@ -417,7 +417,7 @@ if (cluster.isMaster) {
|
|||||||
// there are no more servers open so we will close the IPC channel.
|
// there are no more servers open so we will close the IPC channel.
|
||||||
// Closing the IPC channel will emit a disconnect event
|
// Closing the IPC channel will emit a disconnect event
|
||||||
// in both master and worker on the process object.
|
// in both master and worker on the process object.
|
||||||
// This event will be handled by prepareDeath.
|
// This event will be handled by prepareExit.
|
||||||
self.process.disconnect();
|
self.process.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -49,13 +49,13 @@ else if (cluster.isMaster) {
|
|||||||
fork: false,
|
fork: false,
|
||||||
online: false,
|
online: false,
|
||||||
listening: false,
|
listening: false,
|
||||||
death: false
|
exit: false
|
||||||
},
|
},
|
||||||
equal: {
|
equal: {
|
||||||
fork: false,
|
fork: false,
|
||||||
online: false,
|
online: false,
|
||||||
listening: false,
|
listening: false,
|
||||||
death: false
|
exit: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -63,12 +63,12 @@ else if (cluster.isMaster) {
|
|||||||
events: {
|
events: {
|
||||||
online: false,
|
online: false,
|
||||||
listening: false,
|
listening: false,
|
||||||
death: false
|
exit: false
|
||||||
},
|
},
|
||||||
equal: {
|
equal: {
|
||||||
online: false,
|
online: false,
|
||||||
listening: false,
|
listening: false,
|
||||||
death: false
|
exit: false
|
||||||
},
|
},
|
||||||
states: {
|
states: {
|
||||||
none: false,
|
none: false,
|
||||||
@ -106,7 +106,7 @@ else if (cluster.isMaster) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Kill process when worker is killed
|
//Kill process when worker is killed
|
||||||
cluster.on('death', function() {
|
cluster.on('exit', function() {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ if (cluster.isMaster) {
|
|||||||
assert.equal(msg, 'DONE');
|
assert.equal(msg, 'DONE');
|
||||||
ok = true;
|
ok = true;
|
||||||
});
|
});
|
||||||
worker.on('death', function() {
|
worker.on('exit', function() {
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
|
@ -114,7 +114,7 @@ else if (cluster.isMaster) {
|
|||||||
worker.destroy();
|
worker.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.on('death', function() {
|
worker.on('exit', function() {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ if (cluster.isWorker) {
|
|||||||
var checks = {
|
var checks = {
|
||||||
cluster: {
|
cluster: {
|
||||||
emitDisconnect: false,
|
emitDisconnect: false,
|
||||||
emitDeath: false,
|
emitExit: false,
|
||||||
callback: false
|
callback: false
|
||||||
},
|
},
|
||||||
worker: {
|
worker: {
|
||||||
emitDisconnect: false,
|
emitDisconnect: false,
|
||||||
emitDeath: false,
|
emitExit: false,
|
||||||
state: false,
|
state: false,
|
||||||
suicideMode: false,
|
suicideMode: false,
|
||||||
died: false
|
died: false
|
||||||
@ -69,8 +69,8 @@ if (cluster.isWorker) {
|
|||||||
cluster.once('disconnect', function() {
|
cluster.once('disconnect', function() {
|
||||||
checks.cluster.emitDisconnect = true;
|
checks.cluster.emitDisconnect = true;
|
||||||
});
|
});
|
||||||
cluster.once('death', function() {
|
cluster.once('exit', function() {
|
||||||
checks.cluster.emitDeath = true;
|
checks.cluster.emitExit = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check worker eventes and properties
|
// Check worker eventes and properties
|
||||||
@ -81,8 +81,8 @@ if (cluster.isWorker) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check that the worker died
|
// Check that the worker died
|
||||||
worker.once('death', function() {
|
worker.once('exit', function() {
|
||||||
checks.worker.emitDeath = true;
|
checks.worker.emitExit = true;
|
||||||
checks.worker.died = !alive(worker.process.pid);
|
checks.worker.died = !alive(worker.process.pid);
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@ -97,8 +97,8 @@ if (cluster.isWorker) {
|
|||||||
// events
|
// events
|
||||||
assert.ok(w.emitDisconnect, 'Disconnect event did not emit');
|
assert.ok(w.emitDisconnect, 'Disconnect event did not emit');
|
||||||
assert.ok(c.emitDisconnect, 'Disconnect event did not emit');
|
assert.ok(c.emitDisconnect, 'Disconnect event did not emit');
|
||||||
assert.ok(w.emitDeath, 'Death event did not emit');
|
assert.ok(w.emitExit, 'Exit event did not emit');
|
||||||
assert.ok(c.emitDeath, 'Death event did not emit');
|
assert.ok(c.emitExit, 'Exit event did not emit');
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
assert.equal(w.state, 'disconnected', 'The state property was not set');
|
assert.equal(w.state, 'disconnected', 'The state property was not set');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user