Skip to content

Commit

Permalink
Added error handler 'causalty'
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurer committed Dec 24, 2012
1 parent 89464c2 commit d532ae0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions example.js
Expand Up @@ -18,6 +18,10 @@ var sp = new SpawnMinions();
["./minion.js", "testing12"], ["./minion.js", "testing12"],
["./minion.js", "testing13"] ["./minion.js", "testing13"]
) )
// Executed when a message or data is sent from the process. Used for sending back data instead of text
.causalty(function(e){
console.log("error", e.toString());
})
// Executed when the thread reports STDOUT data event // Executed when the thread reports STDOUT data event
.signalFlare(function(pos, messageData, data){ .signalFlare(function(pos, messageData, data){
// REMOVE THIS TO SEE EACH PROCESSES RESULT // REMOVE THIS TO SEE EACH PROCESSES RESULT
Expand All @@ -40,6 +44,8 @@ var sp = new SpawnMinions();
console.log(e); // Error console.log(e); // Error
}); });


// Remove this to see the queue
return;
var queueCheck = setInterval(function(){ var queueCheck = setInterval(function(){
console.log("queue - " + sp.queue.length); // waiting to process console.log("queue - " + sp.queue.length); // waiting to process
console.log("processQueue - " + sp.processQueue.length); // in process console.log("processQueue - " + sp.processQueue.length); // in process
Expand Down
3 changes: 1 addition & 2 deletions minion.js
@@ -1,5 +1,4 @@
var timeDur = Math.random(2000, 5000) * 10000; var timeDur = Math.random(2000, 5000) * 10000;
console.log(timeDur)
setTimeout(function(){ setTimeout(function(){
console.log(process.argv) console.log(timeDur)
}, timeDur); }, timeDur);
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name" : "spawn-minion" "name" : "spawn-minion"
,"author" : "Andrew Maurer <andrew@maurer.me>" ,"author" : "Andrew Maurer <andrew@maurer.me>"
,"description" : "A module that spawns new threads for each argument passed to it. Creates a queue and limits the number of running processes to CPU count." ,"description" : "A module that spawns new threads for each argument passed to it. Creates a queue and limits the number of running processes to CPU count."
,"version" : "0.2.3" ,"version" : "0.2.4"
,"main" : "spawn-minions.js" ,"main" : "spawn-minions.js"
, "repository" : { , "repository" : {
"type" : "git" "type" : "git"
Expand Down
16 changes: 13 additions & 3 deletions spawn-minions.js
Expand Up @@ -9,7 +9,8 @@ function SpawnMinions(){
this.finishedQueue = []; this.finishedQueue = [];
this._cb = { this._cb = {
report : function(){}, report : function(){},
done : function(){} done : function(){},
incomingData : function(){}
}; };
this.uuid = require("node-uuid"); this.uuid = require("node-uuid");
}; };
Expand All @@ -18,10 +19,10 @@ SpawnMinions.prototype.armyGo = function() {


/* /*
arguments pattern arguments pattern
[ (
[path, arg, arg], [path, arg, arg],
[path, arg, arg] [path, arg, arg]
] )
*/ */


// copy args for queue // copy args for queue
Expand Down Expand Up @@ -51,6 +52,11 @@ SpawnMinions.prototype.signalFlare = function(cb) {
return this; return this;
}; };


SpawnMinions.prototype.causalty = function(cb) {
this._cb.errorHandler = cb;
return this;
};

SpawnMinions.prototype.warReport = function(cb) { SpawnMinions.prototype.warReport = function(cb) {
this._cb.report = cb; this._cb.report = cb;
return this; return this;
Expand Down Expand Up @@ -102,6 +108,10 @@ SpawnMinions.prototype.processJob = function() {
self._cb.incomingData(job.pos, stringdata, job.data); self._cb.incomingData(job.pos, stringdata, job.data);
}); });


node.stderr.on("data", function(){
self._cb.errorHandler.apply(this, arguments)
});

node.on("close", function(e, param){ node.on("close", function(e, param){
var processPos = self.getJob("processQueue", jobUID); var processPos = self.getJob("processQueue", jobUID);
var job = self.processQueue.splice(processPos, 1)[0]; var job = self.processQueue.splice(processPos, 1)[0];
Expand Down

0 comments on commit d532ae0

Please sign in to comment.