Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Fix spawn delay
Browse files Browse the repository at this point in the history
Added logger
  • Loading branch information
Kikobeats committed Feb 22, 2016
1 parent 8c30de3 commit fe846c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
23 changes: 15 additions & 8 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
var path = require('path')
var range = require('lodash.range')
var pkg = require('../package.json')
var eachAsync = require('each-async')
var debug = require('debug')(pkg.name)
var workerFarm = require('worker-farm')
var series = require('run-series')
var minimistOptions = require('./minimist-options')

require('update-notifier')({pkg: pkg}).notify()
Expand All @@ -22,6 +23,8 @@ if (!filename) cli.showHelp()

var flags = cli.flags

debug(flags)

var fileArgs = process.argv.slice(process.argv.indexOf(filename) + 1)
var workers = flags.workers * flags.cores

Expand Down Expand Up @@ -83,20 +86,24 @@ var farmOptions = {
// the first request comes through.
autoStart: true
}

var workersRange = range(workers)
var spawnWorker = workerFarm(farmOptions, path.resolve(filename))

function spawnDelay (workerArgs, cb) {
spawnWorker(workerArgs, process.exit)
setTimeout(cb, flags.delay)
function spawnWorkerDelay (workerArgs) {
return function (cb) {
debug('spawning %s', workerArgs)
spawnWorker(workerArgs, process.exit)
setTimeout(cb, flags.delay)
}
}

function closeFarm () {
workerFarm.end(spawnWorker)
}

eachAsync(workersRange, function (worker, index, next) {
var spawnWorkers = workersRange.map(function (worker) {
var workerArgs = fileArgs.concat(['--worker=' + worker])
return spawnDelay(workerArgs, next)
}, closeFarm)
return spawnWorkerDelay(workerArgs)
})

series(spawnWorkers, closeFarm)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
"worker"
],
"dependencies": {
"each-async": "~1.1.1",
"exists-file": "~1.0.0",
"lodash.range": "~3.1.2",
"meow": "~3.7.0",
"update-notifier": "~0.6.0",
"worker-farm": "~1.3.1"
"worker-farm": "~1.3.1",
"debug": "~2.2.0",
"run-series": "~1.1.4"
},
"devDependencies": {
"git-dirty": "latest",
Expand Down

0 comments on commit fe846c5

Please sign in to comment.