Skip to content
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

feat:add sticky mode support #32

Merged
merged 3 commits into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
coverage/
!test/fixtures/custom-framework-app/node_modules/
.tmp
.vscode
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ $ egg-bin dev

- `--eggPath` egg web framework root path.No default value, must supply.
- `--baseDir` application's root path.default to `process.cwd()`.
- `--port` server port.default to 7001.
- `--cluster` worker process number.default to 1.
- `--port` server port.default to `7001`.
- `--cluster` worker process number.default to `1`.
- `--sticky` start a sticky cluster server.default to `false`.

### debug

Expand Down
8 changes: 8 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ $ npm i egg-bin --save-dev
$ egg-bin dev
```

##### options

- `--eggPath` egg web 框架根目录。必须设置。
- `--baseDir` 应用根目录,默认为 `process.cwd()`。
- `--port` 服务端口,默认为 `7001`。
- `--cluster` 工作进程数量。默认为 `1`.
- `--sticky` 启动 `sticky` 模式服务。默认为 `false`。

### debug

使用 iron-node 调试工具启动应用。
Expand Down
3 changes: 3 additions & 0 deletions lib/start-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ commander
.option('--baseDir [baseDir]')
.option('-p, --port [port]')
.option('--cluster [workers]')
.option('--sticky [sticky]')
Copy link
Member

Choose a reason for hiding this comment

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

[sticky] 不需要

Copy link
Member Author

Choose a reason for hiding this comment

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

改好了

.allowUnknownOption(true)
.parse(process.argv);

const baseDir = commander.baseDir;
const workers = commander.cluster ? Number(commander.cluster) : 1;
const port = commander.port;
const customEgg = commander.eggPath;
const sticky = commander.sticky;

assert(customEgg, 'eggPath required, missing any egg frameworks?');

Expand All @@ -26,6 +28,7 @@ const options = {
workers,
port,
customEgg,
sticky,
};

debug('eggPath:%s options:%j', customEgg, options);
Expand Down
7 changes: 7 additions & 0 deletions test/egg-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe('egg-bin dev', () => {
.end(done);
});

it('should startCluster with --sticky', done => {
coffee.fork(eggBin, [ 'dev', '--port', '6001', '--sticky' ], { cwd: appdir })
.expect('stdout', `{"baseDir":"${appdir}","workers":1,"port":"6001","customEgg":"${customEgg}","sticky":true}\n`)
.expect('code', 0)
.end(done);
});

it('should startCluster with -p', done => {
coffee.fork(eggBin, [ 'dev', '-p', '6001' ], { cwd: appdir })
// .debug()
Expand Down