Skip to content

Commit

Permalink
Add job options for priority and background processing
Browse files Browse the repository at this point in the history
  • Loading branch information
alz committed Feb 23, 2013
1 parent 8fc1d6a commit 9f4892a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/gearman.js
Expand Up @@ -473,8 +473,8 @@ Gearman.prototype.registerWorker = function(name, func){
this.workers[name] = func; this.workers[name] = func;
}; };


Gearman.prototype.submitJob = function(name, payload, uniq){ Gearman.prototype.submitJob = function(name, payload, uniq, options){
return new this.Job(this, name, payload, uniq); return new this.Job(this, name, payload, uniq, (typeof options != "object" ? {} : options));
}; };


// WORKER // WORKER
Expand Down Expand Up @@ -519,8 +519,7 @@ Gearman.prototype.Worker.prototype.error = function(error){
}; };


// JOB // JOB

Gearman.prototype.Job = function(gearman, name, payload, uniq, options){
Gearman.prototype.Job = function(gearman, name, payload, uniq){
Stream.call(this); Stream.call(this);


this.gearman = gearman; this.gearman = gearman;
Expand All @@ -529,7 +528,18 @@ Gearman.prototype.Job = function(gearman, name, payload, uniq){


this.timeoutTimer = null; this.timeoutTimer = null;


gearman.sendCommand("SUBMIT_JOB", name, uniq ? uniq : false, payload, this.receiveHandle.bind(this)); var jobType = "SUBMIT_JOB";
if (typeof options == "object") {
if (typeof options.priority == "string" &&
['high', 'low'].indexOf(options.priority) != -1) {
jobType += "_" + options.priority.toUpperCase();
}

if (typeof options.background == "boolean" && options.background)
jobType += "_BG";
}

gearman.sendCommand(jobType, name, uniq ? uniq : false, payload, !options.background ? this.receiveHandle.bind(this) : false);
}; };
utillib.inherits(Gearman.prototype.Job, Stream); utillib.inherits(Gearman.prototype.Job, Stream);


Expand Down

0 comments on commit 9f4892a

Please sign in to comment.