smarter sharding™ (#732)

This commit is contained in:
Gus Caplan
2016-09-23 15:43:16 -05:00
committed by Amish Shah
parent fc9d049cc1
commit 063be5cee2
4 changed files with 18 additions and 12 deletions

View File

@@ -26,15 +26,19 @@ class Shard {
* The process of the shard
* @type {ChildProcess}
*/
this.process = childProcess.fork(path.resolve(this.manager.file), [id, this.manager.shards.size]);
this.process.once('exit', () => {
if (this.manager.respawn) this.manager.createShard(this.id);
this.process = childProcess.fork(path.resolve(this.manager.file), [], {
env: {
SHARD_ID: this.id, SHARD_COUNT: this.manager.totalShards,
},
});
this.process.on('message', message => {
this.manager.emit('message', this, message);
});
this.process.once('exit', () => {
if (this.manager.respawn) this.manager.createShard(this.id);
});
}
/**