Permalink
Browse files

Merge pull request #9 from alz/master

Job priority and background processing
  • Loading branch information...
2 parents 8fc1d6a + 9f4892a commit e578d3b43d2cd5a63e88c036eb31fda8c697da76 @andris9 committed Feb 25, 2013
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/gearman.js
View
@@ -473,8 +473,8 @@ Gearman.prototype.registerWorker = function(name, func){
this.workers[name] = func;
};
-Gearman.prototype.submitJob = function(name, payload, uniq){
- return new this.Job(this, name, payload, uniq);
+Gearman.prototype.submitJob = function(name, payload, uniq, options){
+ return new this.Job(this, name, payload, uniq, (typeof options != "object" ? {} : options));
};
// WORKER
@@ -519,8 +519,7 @@ Gearman.prototype.Worker.prototype.error = function(error){
};
// JOB
-
-Gearman.prototype.Job = function(gearman, name, payload, uniq){
+Gearman.prototype.Job = function(gearman, name, payload, uniq, options){
Stream.call(this);
this.gearman = gearman;
@@ -529,7 +528,18 @@ Gearman.prototype.Job = function(gearman, name, payload, uniq){
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);

0 comments on commit e578d3b

Please sign in to comment.