worker-farm: pass explicit execArgv to workers

Reviewed By: davidaurelio

Differential Revision: D5002197

fbshipit-source-id: 8f556626321963c103d38ec9865110a39f1a5109
This commit is contained in:
Jean Lauliac 2017-05-04 10:19:33 -07:00 committed by Facebook Github Bot
parent 62b6f4bdc5
commit 35814645c0
4 changed files with 10 additions and 4 deletions

View File

@ -38,6 +38,7 @@ function makeFarm(worker, methods, timeout, maxConcurrentWorkers) {
return workerFarm( return workerFarm(
{ {
autoStart: true, autoStart: true,
execArgv: [],
maxConcurrentCallsPerWorker: 1, maxConcurrentCallsPerWorker: 1,
maxConcurrentWorkers, maxConcurrentWorkers,
maxCallsPerWorker: MAX_CALLS_PER_WORKER, maxCallsPerWorker: MAX_CALLS_PER_WORKER,

View File

@ -27,7 +27,7 @@ const extend = require('xtend')
, ProcessTerminatedError = require('errno').create('ProcessTerminatedError') , ProcessTerminatedError = require('errno').create('ProcessTerminatedError')
, MaxConcurrentCallsError = require('errno').create('MaxConcurrentCallsError') , MaxConcurrentCallsError = require('errno').create('MaxConcurrentCallsError')
function Farm (options: {}, path: string) { function Farm (options: {+execArgv: Array<string>}, path: string) {
this.options = extend(DEFAULT_OPTIONS, options) this.options = extend(DEFAULT_OPTIONS, options)
this.path = path this.path = path
this.activeCalls = 0 this.activeCalls = 0
@ -108,7 +108,7 @@ Farm.prototype.onExit = function (childId) {
Farm.prototype.startChild = function () { Farm.prototype.startChild = function () {
this.childId++ this.childId++
var forked = fork(this.path) var forked = fork(this.path, {execArgv: this.options.execArgv})
, id = this.childId , id = this.childId
, c = { , c = {
send : forked.send send : forked.send

View File

@ -14,10 +14,11 @@
const childProcess = require('child_process'); const childProcess = require('child_process');
const childModule = require.resolve('./child/index'); const childModule = require.resolve('./child/index');
function fork(forkModule: string) { function fork(forkModule: string, options: {|+execArgv: Array<string>|}) {
const child = childProcess.fork(childModule, { const child = childProcess.fork(childModule, {
env: process.env, env: process.env,
cwd: process.cwd(), cwd: process.cwd(),
execArgv: options.execArgv,
}); });
child.send({module: forkModule}); child.send({module: forkModule});

View File

@ -14,7 +14,11 @@ const Farm = require('./farm')
var farms = [] // keep record of farms so we can end() them if required var farms = [] // keep record of farms so we can end() them if required
function farm(options: {}, path: string, methods: Array<string>): {[name: string]: Function} { function farm(
options: {+execArgv: Array<string>},
path: string,
methods: Array<string>,
): {[name: string]: Function} {
var f = new Farm(options, path) var f = new Farm(options, path)
, api = f.setup(methods) , api = f.setup(methods)