From 8a7a8db5988d6eb7990e1ee4e602bf9aad5b8c01 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Wed, 30 Apr 2014 12:01:54 -0400 Subject: [PATCH 1/2] code cleanup - normalize spacing in comments - remove extra newlines - get EventEmitter directly - move os require to top - use fs.existsSync rather than deprecated path --- lib/compute-cluster.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/compute-cluster.js b/lib/compute-cluster.js index aa97784..fa86d10 100644 --- a/lib/compute-cluster.js +++ b/lib/compute-cluster.js @@ -1,8 +1,10 @@ const util = require('util'), path = require('path'), +fs = require('fs'), child_process = require('child_process'), -events = require('events'); +EventEmitter = require('events').EventEmitter, +os = require('os'); // decaying factor for heurstics calculating how much work costs. const MAX_HISTORY = 100; @@ -12,7 +14,7 @@ function ComputeCluster(options) { throw "missing required 'module' argument"; } // is module a file? - if (!path.existsSync(options.module)) { + if (!fs.existsSync(options.module)) { throw "module doesn't exist: " + options.module; } if (options.max_processes && @@ -26,11 +28,11 @@ function ComputeCluster(options) { throw "when provided, max_request_time must be a number"; } - events.EventEmitter.call(this); + EventEmitter.call(this); // an array of child processes this._kids = {}; - this._MAX_KIDS = (options.max_processes || Math.ceil(require('os').cpus().length * 1.25)); + this._MAX_KIDS = (options.max_processes || Math.ceil(os.cpus().length * 1.25)); this._work_q = []; this._exiting = false; this._exit_cb; @@ -43,7 +45,7 @@ function ComputeCluster(options) { this._jobs_run = 0; }; -util.inherits(ComputeCluster, events.EventEmitter); +util.inherits(ComputeCluster, EventEmitter); ComputeCluster.prototype._onWorkerExit = function(pid) { var self = this; @@ -72,8 +74,8 @@ ComputeCluster.prototype._getEnvForWorker = function() { env[i] = process.env[i]; } - delete env.NODE_WORKER_ID; //Node.js cluster worker marker for v0.6 - delete env.NODE_UNIQUE_ID; //Node.js cluster worker marker for v0.7 + delete env.NODE_WORKER_ID; // Node.js cluster worker marker for v0.6 + delete env.NODE_UNIQUE_ID; // Node.js cluster worker marker for v0.7 return env; }; @@ -85,7 +87,7 @@ ComputeCluster.prototype._getFreeWorker = function() { if (!this._kids[i].job) return this._kids[i]; } - // no workers! can we spawn one? + // no workers! can we spawn one? if (Object.keys(this._kids).length < this._MAX_KIDS) { var k = { worker: child_process.fork( @@ -136,8 +138,8 @@ ComputeCluster.prototype._runWorkOnWorker = function(work, worker) { worker.job = work; }; - // assign as many work units from work_q as possible to avialable - // compute processes +// assign as many work units from work_q as possible to avialable +// compute processes ComputeCluster.prototype._assignWork = function() { while (this._work_q.length > 0) { var worker = this._getFreeWorker(); @@ -197,4 +199,3 @@ ComputeCluster.prototype.exit = function(cb) { }; module.exports = ComputeCluster; - From c1c1b8ed04be7600aa9e454b00e90592b63ce630 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Wed, 30 Apr 2014 12:05:43 -0400 Subject: [PATCH 2/2] move vows to devDependencies --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index de1622a..b1ec0fa 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,9 @@ "engines": { "node": ">= 0.6.2" }, - "dependencies": { + "devDependencies": { "vows": "0.6.0" }, - "devDependencies": {}, "scripts": { "test": "vows" },