Skip to content

Commit

Permalink
mini refactor God/Reload.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jshkurti committed Dec 5, 2014
1 parent 59f6793 commit cf94517
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/God/Reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function softReload(God, id, cb) {
clearTimeout(timer_3);
softCleanDeleteProcess();
console.log('-reload- New worker listening');
}
};

// Bind to know when the new process is up
new_worker.once('listening', onListen);
Expand All @@ -68,16 +68,15 @@ function softReload(God, id, cb) {
clearTimeout(timer_2);
console.log('-reload- Old worker disconnected');
God.deleteProcessId(t_key, cb);
}
};

old_worker.once('disconnect', cleanUp);

try {
old_worker.send('shutdown');
old_worker.send && old_worker.send('shutdown');
} catch(e) {
clearTimeout(timer_1);
clearTimeout(timer_2);
old_worker.removeListener('disconnect', cleanUp);
console.error('Worker %d is already disconnected', old_worker.pm2_env.pm_id);
return God.deleteProcessId(t_key, cb);
}
Expand All @@ -86,19 +85,18 @@ function softReload(God, id, cb) {
timer_2 = setTimeout(function () {
old_worker.removeListener('disconnect', cleanUp);
try {
old_worker.destroy();
old_worker.destroy && old_worker.destroy();
} catch (e) {
console.error('Worker %s is already disconnected', old_worker.pm2_env.pm_id);
}
God.deleteProcessId(t_key, cb);
}, 2000);

try {
old_worker.disconnect();
old_worker.disconnect && old_worker.disconnect();
} catch(e) {
clearTimeout(timer_2);
console.error(e.stack || e);
old_worker.removeListener('disconnect', cleanUp);
console.error('Worker %s is already disconnected', old_worker.pm2_env.pm_id);
return God.deleteProcessId(t_key, cb);
}
Expand Down Expand Up @@ -147,7 +145,7 @@ function hardReload(God, id, cb) {
clearTimeout(timer);
console.log('-reload- New worker listening');
cleanDeleteProcess();
}
};

// Bind to know when the new process is up
new_worker.once('listening', onListen);
Expand All @@ -168,12 +166,11 @@ function hardReload(God, id, cb) {
var timer_2 = setTimeout(function () {
old_worker.removeListener('disconnect', cleanUp);
try {
old_worker.destroy();
God.deleteProcessId(t_key, cb);
old_worker.destroy && old_worker.destroy();
} catch (e) {
console.error('Worker %d is already disconnected', old_worker.pm2_env.pm_id);
God.deleteProcessId(t_key, cb);
}
God.deleteProcessId(t_key, cb);
}, 2000);

old_worker.once('disconnect', cleanUp);
Expand All @@ -183,7 +180,6 @@ function hardReload(God, id, cb) {
} catch(e) {
clearTimeout(timer_2);
console.error(e.stack || e);
old_worker.removeListener('disconnect', cleanUp);
God.deleteProcessId(t_key, cb);
console.error('Worker %d is already disconnected', old_worker.pm2_env.pm_id);
}
Expand Down

0 comments on commit cf94517

Please sign in to comment.