Skip to content

Commit

Permalink
Merge pull request #4691 from spalger/fix/serverManualRestart
Browse files Browse the repository at this point in the history
[cluster] don't be so picky about manual restart command
  • Loading branch information
rashidkpc committed Aug 19, 2015
2 parents 6ad85ea + 667eac1 commit 8a2e4da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions disabledPlugins/sense
Submodule sense added at fb7fd9
37 changes: 22 additions & 15 deletions src/cli/cluster/ClusterManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let cluster = require('cluster');
let { join } = require('path');
let { startsWith, debounce, compact, invoke, bindAll, once } = require('lodash');
let { debounce, compact, invoke, bindAll, once } = require('lodash');

let Log = require('../Log');
let Worker = require('./Worker');
Expand Down Expand Up @@ -81,25 +81,32 @@ module.exports = class ClusterManager {
}

setupManualRestart() {
let input = '';
let clear = () => input = '';
let clearSoon = debounce(clear, 1250);
let readline = require('readline');
let rl = readline.createInterface(process.stdin, process.stdout);

process.stdin.on('data', chunk => {
input += chunk.toString('utf8');
let nls = 0;
let clear = () => nls = 0;
let clearSoon = debounce(clear, 2000);

if (input === '\n') {
// wait for final \n
clearSoon();
}
else if (startsWith(input, '\n\n')) {
rl.setPrompt('');
rl.prompt();

rl.on('line', line => {
nls = line.trim() ? 0 : nls + 1;
if (nls >= 2) {
clearSoon.cancel();
this.server.start();
clear();
}
else {
clear();
this.server.start();
} else {
clearSoon();
}

rl.prompt();
});

rl.on('SIGINT', () => {
rl.pause();
process.kill(process.pid, 'SIGINT');
});
}

Expand Down

0 comments on commit 8a2e4da

Please sign in to comment.