Skip to content
Browse files

update

  • Loading branch information...
1 parent bdcef77 commit d33402da56bab656e380eaf79860229bfc9915ac andris9 committed
Showing with 21 additions and 7 deletions.
  1. +20 −6 lib/gearman.js
  2. +1 −1 package.json
View
26 lib/gearman.js
@@ -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];
@@ -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];
}
}
@@ -417,12 +421,15 @@ 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);
}
};
@@ -430,11 +437,14 @@ Gearman.prototype.receive_WORK_DATA = function(handle, 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");
+ }
}
};
@@ -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;
View
2 package.json
@@ -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":[
{

0 comments on commit d33402d

Please sign in to comment.
Something went wrong with that request. Please try again.