|
@ -128,13 +128,13 @@ This can be used to log worker activity, and create you own timeout. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cluster.on('fork', function(worker) { |
|
|
cluster.on('fork', function(worker) { |
|
|
timeouts[worker.uniqueID] = setTimeout(errorMsg, 2000); |
|
|
timeouts[worker.id] = setTimeout(errorMsg, 2000); |
|
|
}); |
|
|
}); |
|
|
cluster.on('listening', function(worker, address) { |
|
|
cluster.on('listening', function(worker, address) { |
|
|
clearTimeout(timeouts[worker.uniqueID]); |
|
|
clearTimeout(timeouts[worker.id]); |
|
|
}); |
|
|
}); |
|
|
cluster.on('exit', function(worker, code, signal) { |
|
|
cluster.on('exit', function(worker, code, signal) { |
|
|
clearTimeout(timeouts[worker.uniqueID]); |
|
|
clearTimeout(timeouts[worker.id]); |
|
|
errorMsg(); |
|
|
errorMsg(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -183,7 +183,7 @@ the process is stuck in a cleanup or if there are long-living |
|
|
connections. |
|
|
connections. |
|
|
|
|
|
|
|
|
cluster.on('disconnect', function(worker) { |
|
|
cluster.on('disconnect', function(worker) { |
|
|
console.log('The worker #' + worker.uniqueID + ' has disconnected'); |
|
|
console.log('The worker #' + worker.id + ' has disconnected'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
## Event: 'exit' |
|
|
## Event: 'exit' |
|
@ -266,12 +266,12 @@ The method takes an optional callback argument which will be called when finishe |
|
|
* {Object} |
|
|
* {Object} |
|
|
|
|
|
|
|
|
In the cluster all living worker objects are stored in this object by there |
|
|
In the cluster all living worker objects are stored in this object by there |
|
|
`uniqueID` as the key. This makes it easy to loop through all living workers. |
|
|
`id` as the key. This makes it easy to loop through all living workers. |
|
|
|
|
|
|
|
|
// Go through all workers |
|
|
// Go through all workers |
|
|
function eachWorker(callback) { |
|
|
function eachWorker(callback) { |
|
|
for (var uniqueID in cluster.workers) { |
|
|
for (var id in cluster.workers) { |
|
|
callback(cluster.workers[uniqueID]); |
|
|
callback(cluster.workers[id]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
eachWorker(function(worker) { |
|
|
eachWorker(function(worker) { |
|
@ -279,10 +279,10 @@ In the cluster all living worker objects are stored in this object by there |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
Should you wish to reference a worker over a communication channel, using |
|
|
Should you wish to reference a worker over a communication channel, using |
|
|
the worker's uniqueID is the easiest way to find the worker. |
|
|
the worker's unique id is the easiest way to find the worker. |
|
|
|
|
|
|
|
|
socket.on('data', function(uniqueID) { |
|
|
socket.on('data', function(id) { |
|
|
var worker = cluster.workers[uniqueID]; |
|
|
var worker = cluster.workers[id]; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
## Class: Worker |
|
|
## Class: Worker |
|
@ -291,12 +291,12 @@ A Worker object contains all public information and method about a worker. |
|
|
In the master it can be obtained using `cluster.workers`. In a worker |
|
|
In the master it can be obtained using `cluster.workers`. In a worker |
|
|
it can be obtained using `cluster.worker`. |
|
|
it can be obtained using `cluster.worker`. |
|
|
|
|
|
|
|
|
### worker.uniqueID |
|
|
### worker.id |
|
|
|
|
|
|
|
|
* {String} |
|
|
* {String} |
|
|
|
|
|
|
|
|
Each new worker is given its own unique id, this id is stored in the |
|
|
Each new worker is given its own unique id, this id is stored in the |
|
|
`uniqueID`. |
|
|
`id`. |
|
|
|
|
|
|
|
|
While a worker is alive, this is the key that indexes it in |
|
|
While a worker is alive, this is the key that indexes it in |
|
|
cluster.workers |
|
|
cluster.workers |
|
@ -434,8 +434,8 @@ in the master process using the message system: |
|
|
|
|
|
|
|
|
// Start workers and listen for messages containing notifyRequest |
|
|
// Start workers and listen for messages containing notifyRequest |
|
|
cluster.autoFork(); |
|
|
cluster.autoFork(); |
|
|
Object.keys(cluster.workers).forEach(function(uniqueID) { |
|
|
Object.keys(cluster.workers).forEach(function(id) { |
|
|
cluster.workers[uniqueID].on('message', messageHandler); |
|
|
cluster.workers[id].on('message', messageHandler); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|