When using node.js cluster, how to access a worker's environment when it dies? -


i'm using node.js cluster module create worker processes. , set custom variable in each worker's environment fork it.

i need read custom variable when worker dies, when worker dies, can't access environment object anymore.

this tried far:

var cluster = require('cluster'),     os = require('os');  if (cluster.ismaster) {      cluster.on('exit', function (worker, code, signal) {          console.log('worker ' + worker.process.pid + ' died');          var x = {             workerid: worker.process.env.workerid // undefined.         };         cluster.fork(x);     });      (var = 0; < os.cpus().length; i++) {         var x = {             workerid:         };         cluster.fork(x);     }  } else {     console.log("workerid: ", process.env.workerid);      // simulate exeption:     throw "fakeerror";  } 

i know that's not gonna work, question is: how access latest state of worker's envoronment right before death?

it seems env set in worker's process , not accessible in master. master have primitive information workers process. can want like:

// fork workers. (var = 0; < numcpus; i++) {     var env = {workerid: i},         newworker = cluster.fork(env);     newworker.process.env = env; }  cluster.on('exit', function (worker, code, signal) {     console.log('worker ', worker.process.env.workerid, ' died');     var env = worker.process.env,         newworker = cluster.fork(env);     newworker.process.env = env; }); 

i hope helps you. whenever workers change env, should send message master , inform changes, so, master can update information.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -