From ed08ed159d0cefc9df71c21157d9076239a3059a Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sun, 3 Feb 2019 16:30:32 -0500 Subject: [PATCH] feat: pass farm options --- bin/cli/index.js | 23 +++++++++++++++++++++-- examples/basic/README.md | 6 ++++-- examples/basic/index.js | 13 ++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/bin/cli/index.js b/bin/cli/index.js index 4218adf..0aa81a4 100755 --- a/bin/cli/index.js +++ b/bin/cli/index.js @@ -26,7 +26,15 @@ if (!filename) cli.showHelp() const { file: fileOpts } = argv const { flags: farmOpts } = cli -const { delayBetweenWorkers } = farmOpts +const { + maxRetries, + autoStart, + maxCallTime, + maxConcurrentCalls, + delayBetweenWorkers, + maxConcurrentWorkers, + maxConcurrentCallsPerWorker +} = farmOpts const numWorkers = getNumWorkers(farmOpts) const workersRange = [...Array(numWorkers).keys()] const spawnWorkers = workersRange.map(spawnWorker) @@ -37,7 +45,18 @@ function spawnWorker (id) { function worker (cb) { debug('creating %o', parsedArgs) - farm(parsedArgs, process.exit) + farm( + { + ...parsedArgs, + maxConcurrentWorkers, + maxConcurrentCallsPerWorker, + maxRetries, + autoStart, + maxCallTime, + maxConcurrentCalls + }, + process.exit + ) return setTimeout(cb, delayBetweenWorkers) } diff --git a/examples/basic/README.md b/examples/basic/README.md index fc2e646..db6245b 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -1,5 +1,7 @@ -# Basic +# Shared memory + +An example for illustrating that the memory can be shared between workers in the same core. ```bash -$ DEBUG=farm-cli farm -w 2 -n 5 -d 0 examples/basic --your-file-flags foo=bar +$ DEBUG=farm-cli farm -n 1 -w 5 -d 0 examples/basic --your-file-flags foo=bar ``` diff --git a/examples/basic/index.js b/examples/basic/index.js index 6ae6082..912704b 100644 --- a/examples/basic/index.js +++ b/examples/basic/index.js @@ -2,12 +2,19 @@ const shared = [] -module.exports = function (opts) { - const { worker } = opts +module.exports = function (opts, cb) { + const { + isMaster, + worker, + maxConcurrentCallsPerWorker, + maxConcurrentWorkers + } = opts + const total = maxConcurrentCallsPerWorker * maxConcurrentWorkers console.log('-----------------------------') - console.log(`Hello I'm worker #${worker}`) + console.log(`Hello I'm worker #${worker} ${isMaster ? '(master)' : ''}`) const printSharedWorkers = shared.join(' ') || 'none' console.log(`The shared variable was visited by ${printSharedWorkers}`) shared.push(`#${worker}`) console.log('-----------------------------\n') + if (total === worker + 1) return cb() }