Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add job options for priority and background processing

  • Loading branch information...
commit 9f4892add190170c730572d7c3f9e6f1497b7410 1 parent 8fc1d6a
@alz alz authored
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/gearman.js
View
20 lib/gearman.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.