Skip to content

Commit

Permalink
feat: supports serialization of options
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Feb 13, 2020
1 parent 423726d commit 59e8612
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ startCluster(options, () => {

## Options

| Param | Type | Description |
| ------------ | --------- | ---------------------------------------- |
| baseDir | `String` | directory of application |
| framework | `String` | specify framework that can be absolute path or npm package |
| plugins | `Object` | plugins for unittest |
| workers | `Number` | numbers of app workers |
| sticky | `Boolean` | sticky mode server |
| port | `Number` | port |
| https | `Object` | start a https server, note: `key` / `cert` / `ca` should be full path to file |
| require | `Array\|String` | will inject into worker/agent process |
| pidFile | `String` | will save master pid to this file |
| Param | Type | Description |
| --------------- | --------------- | ----------------------------------------------------------------------------- |
| baseDir | `String` | directory of application |
| framework | `String` | specify framework that can be absolute path or npm package |
| plugins | `Object` | plugins for unittest |
| workers | `Number` | numbers of app workers |
| sticky | `Boolean` | sticky mode server |
| port | `Number` | port |
| https | `Object` | start a https server, note: `key` / `cert` / `ca` should be full path to file |
| require | `Array\|String` | will inject into worker/agent process |
| pidFile | `String` | will save master pid to this file |
| [serialization] | `json|advanced` | default: 'json'. 'advanced' requires Node.js >= 10.16.0 |

## Env

Expand All @@ -71,3 +72,5 @@ EGG_AGENT_CLOSE_TIMEOUT: agent worker boot timeout value
## License

[MIT](LICENSE)

[serialization]:https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#advanced-serialization-for-ipc
12 changes: 12 additions & 0 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class Master extends EventEmitter {
const frameworkPath = this.options.framework;
const frameworkPkg = utility.readJSONSync(path.join(frameworkPath, 'package.json'));

/* istanbul ignore next */
if (this.options.serialization && !semver.gte(process.version, '12.16.0')) {
const err = new Error(`[master] agent_worker options.serialization requires Node.js >= v12.16.0`);
this.logger.error(err);
}

this.log(`[master] =================== ${frameworkPkg.name} start =====================`);
this.logger.info(`[master] node version ${process.version}`);
/* istanbul ignore next */
Expand Down Expand Up @@ -248,6 +254,12 @@ class Master extends EventEmitter {
const debugPort = process.env.EGG_AGENT_DEBUG_PORT || 5800;
if (this.options.isDebug) opt.execArgv = process.execArgv.concat([ `--${semver.gte(process.version, '8.0.0') ? 'inspect' : 'debug'}-port=${debugPort}` ]);

if (semver.gte(process.version, '12.16.0')) {
if (this.options.serialization) {
opt.serialization = this.options.serialization;
}
}

const agentWorker = childprocess.fork(this.getAgentWorkerFile(), args, opt);
agentWorker.status = 'starting';
agentWorker.id = ++this.agentWorkerIndex;
Expand Down

0 comments on commit 59e8612

Please sign in to comment.