worker-farm
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -9,2 +9,3 @@ const DEFAULT_OPTIONS = { | ||
, forcedKillTime : 100 | ||
, autoStart : false | ||
} | ||
@@ -61,2 +62,7 @@ | ||
if (this.options.autoStart) { | ||
while (this.activeChildren < this.options.maxConcurrentWorkers) | ||
this.startChild() | ||
} | ||
return iface | ||
@@ -63,0 +69,0 @@ } |
{ | ||
"name": "worker-farm", | ||
"description": "Distribute processing tasks to child processes with an über-simple API and baked-in durability & custom concurrency options.", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/rvagg/node-worker-farm", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -112,2 +112,3 @@ # Worker Farm [![Build Status](https://secure.travis-ci.org/rvagg/node-worker-farm.png)](http://travis-ci.org/rvagg/node-worker-farm) | ||
, maxRetries : Infinity | ||
, autoStart : false | ||
} | ||
@@ -128,2 +129,4 @@ ``` | ||
* **<code>autoStart</code>** when set to `true` will start the workers as early as possible. Use this when your workers have to do expensive initialization. That way they'll be ready when the first request comes through. | ||
### workerFarm.end(farm) | ||
@@ -130,0 +133,0 @@ |
@@ -52,2 +52,7 @@ var fs = require('fs') | ||
} | ||
} | ||
} | ||
var started = Date.now() | ||
module.exports.uptime = function(callback) { | ||
callback(null, Date.now() - started) | ||
} |
@@ -121,2 +121,22 @@ var tape = require('tape') | ||
tape('auto start workers', function (t) { | ||
t.plan(4) | ||
var child = workerFarm({ maxConcurrentWorkers: 3, autoStart: true }, childPath, ['uptime']) | ||
, pids = [] | ||
, i = 3 | ||
, delay = 150 | ||
setTimeout(function() { | ||
while (i--) | ||
child.uptime(function (err, uptime) { | ||
t.ok(uptime > 10, 'child has been up before the request') | ||
}) | ||
workerFarm.end(child, function () { | ||
t.ok(true, 'workerFarm ended') | ||
}) | ||
}, delay) | ||
}) | ||
// use the returned pids to check that we're using a child process per | ||
@@ -231,3 +251,3 @@ // call when we set maxCallsPerWorker = 1 even when we have maxConcurrentWorkers = 1 | ||
var time = Date.now() - start | ||
t.ok(time > 100 && time < 175, 'processed tasks concurrently (' + time + 'ms)') | ||
t.ok(time > 100 && time < 200, 'processed tasks concurrently (' + time + 'ms)') | ||
workerFarm.end(child, function () { | ||
@@ -433,2 +453,2 @@ t.ok(true, 'workerFarm ended') | ||
}) | ||
}) | ||
}) |
41673
841
142