Skip to content

feat: get clusterPort #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const childprocess = require('child_process');
const cfork = require('cfork');
const ready = require('get-ready');
const debug = require('debug')('egg-cluster');
const detectPort = require('detect-port');
const ConsoleLogger = require('egg-logger').EggConsoleLogger;

const parseOptions = require('./utils/options');
Expand Down Expand Up @@ -77,7 +78,17 @@ class Master extends EventEmitter {

this.onExit();

this.forkAgentWorker();
detectPort((err, port) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个加进去后, egg-bin 那边还需要检测么?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

egg-bin 是另外一个功能?这个是 cluster-client 的端口

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

喔喔

/* istanbul ignore if */
if (err) {
err.name = 'ClusterPortConflictError';
err.message = '[master] try get free port error, ' + err.message;
this.logger.error(err);
return;
}
this.options.clusterPort = port;
this.forkAgentWorker();
});
}

forkAgentWorker() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"cfork": "^1.6.0",
"cluster-reload": "^1.0.2",
"debug": "^2.4.5",
"detect-port": "^1.1.0",
"egg-logger": "^1.5.0",
"get-ready": "^1.0.0",
"sendmessage": "^1.1.0"
Expand Down
1 change: 1 addition & 0 deletions test/master.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('test/lib/cluster/master.test.js', () => {

app.expect('stdout', /egg start/)
.expect('stdout', /egg started/)
.expect('stdout', /\\"clusterPort\\":\d+/)
.expect('code', 0)
.end(done);
});
Expand Down