Skip to content

Commit

Permalink
feat: add sticky mode support (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot authored and fengmk2 committed Feb 14, 2017
1 parent 064e7d8 commit f5a1152
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
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')
.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

0 comments on commit f5a1152

Please sign in to comment.