Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Nov 28, 2011
1 parent bdcef77 commit d33402d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions lib/gearman.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Gearman.prototype.closeConnection = function(){
for(i in this.currentJobs){
if(this.currentJobs.hasOwnProperty(i)){
if(this.currentJobs[i]){
this.currentJobs[i].abort();
this.currentJobs[i].emit("error", new Error("Job failed"));
}
delete this.currentJobs[i];
Expand All @@ -188,6 +189,9 @@ Gearman.prototype.closeConnection = function(){
// clear current workers
for(i in this.currentWorkers){
if(this.currentWorkers.hasOwnProperty(i)){
if(this.currentWorkers[i]){
this.currentWorkers[i].finished = true;
}
delete this.currentWorkers[i];
}
}
Expand Down Expand Up @@ -417,24 +421,30 @@ Gearman.prototype.receive_WORK_FAIL = function(handle){
var job;
if((job = this.currentJobs[handle])){
delete this.currentJobs[handle];
job.emit("error", new Error("Job failed"));
if(!job.aborted){
job.abort();
job.emit("error", new Error("Job failed"));
}
}
};

Gearman.prototype.receive_WORK_DATA = function(handle, payload){
if(this.currentJobs[handle]){
if(this.currentJobs[handle] && !this.currentJobs[handle].aborted){
this.currentJobs[handle].emit("data", payload);
}
};

Gearman.prototype.receive_WORK_COMPLETE = function(handle, payload){
var job;
if((job = this.currentJobs[handle])){
if(payload){
job.emit("data", payload);
}
delete this.currentJobs[handle];
job.emit("end");
if(!job.aborted){
if(payload){
job.emit("data", payload);
}

job.emit("end");
}
}
};

Expand Down Expand Up @@ -512,6 +522,10 @@ Gearman.prototype.Job = function(gearman, name, payload){
};
utillib.inherits(Gearman.prototype.Job, Stream);

Gearman.prototype.Job.prototype.abort = function(){
this.aborted = true;
}

Gearman.prototype.Job.prototype.receiveHandle = function(handle){
if(handle){
this.handle = handle;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-gearman",
"description": "Simple Gearman client/worker module for Node.JS",
"version": "0.1.1",
"version": "0.1.2",
"author" : "Andris Reinman",
"maintainers":[
{
Expand Down

0 comments on commit d33402d

Please sign in to comment.