From 966d8d1a398dfb75bef107c1868e0ec2a60fd323 Mon Sep 17 00:00:00 2001 From: "James P. Javery" Date: Wed, 18 Dec 2013 12:11:00 -0600 Subject: [PATCH] Allow new env on restart --- README.md | 9 +++++---- cluster-master.js | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d3e2a8..e896ac7 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,11 @@ clusterMaster.quitHard() Set the cluster size to `n`. This will disconnect extra nodes and/or spin up new nodes, as needed. Done by default on restarts. -### clusterMaster.restart(cb) +### clusterMaster.restart(env, cb) -One by one, shut down nodes and spin up new ones. Callback is called -when finished. +One by one, shut down nodes and spin up new ones. New workers will +receive `env`, instead of the envs passed in config. Callback is called +when finished. `env` and `cb` are optional. ### clusterMaster.quit() @@ -129,7 +130,7 @@ The REPL provides you with access to these objects or functions: * `help` - display these commands * `repl` - access the REPL * `resize(n)` - resize the cluster to `n` workers -* `restart(cb)` - gracefully restart workers, cb is optional +* `restart(env, cb)` - gracefully restart workers, env and cb are optional * `stop()` - gracefully stop workers and master * `kill()` - forcefully kill workers and master * `cluster` - node.js cluster module diff --git a/cluster-master.js b/cluster-master.js index 17894d9..d70bb43 100644 --- a/cluster-master.js +++ b/cluster-master.js @@ -148,7 +148,7 @@ function setupRepl () { 'help - display these commands', 'repl - access the REPL', 'resize(n) - resize the cluster to `n` workers', - 'restart(cb) - gracefully restart workers, cb is optional', + 'restart(env, cb) - gracefully restart workers, env and cb are optional', 'stop() - gracefully stop workers and master', 'kill() - forcefully kill workers and master', 'cluster - node.js cluster module', @@ -304,7 +304,7 @@ function forkListener () { }) } -function restart (cb) { +function restart (env_, cb) { if (restarting) { debug("Already restarting. Cannot restart yet.") return @@ -312,6 +312,11 @@ function restart (cb) { restarting = true + if (arguments.length == 1 && env_ && {}.toString.call(env_) == '[object Function]') + cb = env_, env_ = undefined + + if (env_) env = env_ + // graceful restart. // all the existing workers get killed, and this // causes new ones to be spawned. If there aren't