Permalink
Browse files

client uuids

  • Loading branch information...
1 parent ef00bd6 commit 922205e9fc70486ba0c6fe2fcd19113b52bf9255 @smith smith committed May 19, 2011
Showing with 36 additions and 29 deletions.
  1. +4 −0 HISTORY.md
  2. +3 −0 lib/job.js
  3. +3 −1 lib/packet/requests.js
  4. +1 −1 package.json
  5. +1 −2 test/test-job.js
  6. +24 −25 test/test-packet.js
View
@@ -1,5 +1,9 @@
# History
+## 0.4.0
+
+* Unique client ids
+
## 0.3.0 / 2011-05-02
* Background job support
View
@@ -1,5 +1,6 @@
var gearman = require("gearman"),
inherits = require("util").inherits,
+ uuid = require("node-uuid"),
util = require("./util"),
extend = util.extend,
debug = util.debug,
@@ -11,6 +12,7 @@ var gearman = require("gearman"),
Job = function (options) {
if (!(this instanceof Job)) { return new Job(options); }
extend(this, options);
+ this.id = this.id || uuid("binary");
this.client = this.client || gearman.createClient();
this.priority = this.priority || "normal";
@@ -23,6 +25,7 @@ exports.Job = Job;
Job.prototype.submit = function () {
var client = this.client,
data = {
+ id: this.id,
name: this.name,
data: this.data,
encoding: this.encoding
View
@@ -6,6 +6,7 @@ function submitJob(options) {
options = options || {};
var data = options.data || 0,
name = options.name,
+ id = options.id || new Buffer([1]), // uuid
encoding = options.encoding;
if (typeof name !== "string") {
@@ -20,7 +21,8 @@ function submitJob(options) {
return binary.put().
put(new Buffer(name, "ascii")).
word8(0).
- word8(0). // TODO: unique client ids
+ put(id).
+ word8(0).
put(data).
buffer();
}
View
@@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/cramerdev/gearman-node.git"
},
- "dependencies": { "binary": ">=0.0.0" },
+ "dependencies": { "binary": ">=0", "node-uuid": ">=0" },
"devDependencies": { "nodeunit": "~0.4" },
"scripts": { "test": "nodeunit test" }
}
View
@@ -7,15 +7,14 @@ var gearman = require("gearman"),
// XXX: These need a real gearman server running on localhost:4730 and
// test/fixtures/worker.rb running. Need to make a mock server or something.
-// gearman.debug = true;
-
client = gearman.createClient();
job = client.submitJob("test", "test", { encoding: "utf8" });
module.exports = testCase({
"Job": function (test) {
test.ok(job instanceof EventEmitter,
"Job instances are EventEmitters");
+ test.ok(job.id instanceof Buffer, "Job id is a Buffer");
test.equal("normal", job.priority, "default priority is normal");
test.done();
},
View
@@ -16,63 +16,62 @@ exports["encode"] = function (test) {
exports["encode SUBMIT_JOB"] = function (test) {
// examples
- // \0REQ-SUBMIT_JOB-6-test\0-\0/
- var empty = new Buffer([0,0x52,0x45,0x51,0,0,0,0x7,0,0,0,0x6,0x74,0x65,0x73,0x74,0,0]),
- // \0REQ-SUBMIT_JOB-7-test\0-\0-a/
- data = new Buffer([0,0x52,0x45,0x51,0,0,0,0x7,0,0,0,0x7,0x74,0x65,0x73,0x74,0,0,0x61]);
-
- test.throws(function () { packet.encode({ type: "SUBMIT_JOB" }); }, "job must have a name string");
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test" }), empty);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test", data: "a", encoding: "utf8" }), data);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test", data: new Buffer([0x61]) }), data);
+ // \0REQ-SUBMIT_JOB-7-test-\0-1-\0
+ var empty = new Buffer([0,0x52,0x45,0x51,0,0,0,0x7,0,0,0,7,0x74,0x65,0x73,0x74,0,1,0]),
+ // \0REQ-SUBMIT_JOB-8-test-\0-1-\0-a
+ data = new Buffer([0,0x52,0x45,0x51,0,0,0,0x7,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
+ test.throws(function () { packet.encode({ type: "SUBMIT_JOB", id: null }); }, "job must have a name string");
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test", id: null }), empty);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test", data: "a", encoding: "utf8", id: null }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB", name: "test", data: new Buffer([0x61]), id: null }), data);
test.done();
};
exports["encode SUBMIT_JOB_HIGH"] = function (test) {
- // \0REQ-SUBMIT_JOB_HIGH-7-test\0-\0-a/
- var data = new Buffer([0,0x52,0x45,0x51,0,0,0,21,0,0,0,7,0x74,0x65,0x73,0x74,0,0,0x61]);
+ // \0REQ-SUBMIT_JOB_HIGH-8-test\0-1-\0-a/
+ var data = new Buffer([0,0x52,0x45,0x51,0,0,0,21,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB_HIGH", name: "test", data: "a", encoding: "utf8" }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB_HIGH", name: "test", data: "a", encoding: "utf8", id: null }), data);
test.done();
};
exports["encode SUBMIT_JOB_LOW"] = function (test) {
- // \0REQ-SUBMIT_JOB_LOW-7-test\0-\0-a/
- var data = new Buffer([0,0x52,0x45,0x51,0,0,0,33,0,0,0,7,0x74,0x65,0x73,0x74,0,0,0x61]);
+ // \0REQ-SUBMIT_JOB_LOW-8-test\0-1-\0-a/
+ var data = new Buffer([0,0x52,0x45,0x51,0,0,0,33,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB_LOW", name: "test", data: "a", encoding: "utf8" }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB_LOW", name: "test", data: "a", encoding: "utf8", id: null }), data);
test.done();
};
exports["encode SUBMIT_JOB_BG"] = function (test) {
- // \0REQ-SUBMIT_JOB_BG-7-test\0-\0-a/
- var data = new Buffer([0,0x52,0x45,0x51,0,0,0,18,0,0,0,7,0x74,0x65,0x73,0x74,0,0,0x61]);
+ // \0REQ-SUBMIT_JOB_BG-8-test\0-1-\0-a/
+ var data = new Buffer([0,0x52,0x45,0x51,0,0,0,18,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB_BG", name: "test", data: "a", encoding: "utf8" }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB_BG", name: "test", data: "a", encoding: "utf8", id: null }), data);
test.done();
};
exports["encode SUBMIT_JOB_HIGH_BG"] = function (test) {
- // \0REQ-SUBMIT_JOB_HIGH_BG-7-test\0-\0-a/
- var data = new Buffer([0,0x52,0x45,0x51,0,0,0,32,0,0,0,7,0x74,0x65,0x73,0x74,0,0,0x61]);
+ // \0REQ-SUBMIT_JOB_HIGH_BG-8-test\0-1-\0-a/
+ var data = new Buffer([0,0x52,0x45,0x51,0,0,0,32,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB_HIGH_BG", name: "test", data: "a", encoding: "utf8" }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB_HIGH_BG", name: "test", data: "a", encoding: "utf8", id: null }), data);
test.done();
};
exports["encode SUBMIT_JOB_LOW_BG"] = function (test) {
- // \0REQ-SUBMIT_JOB_LOW_BG-7-test\0-\0-a/
- var data = new Buffer([0,0x52,0x45,0x51,0,0,0,34,0,0,0,7,0x74,0x65,0x73,0x74,0,0,0x61]);
+ // \0REQ-SUBMIT_JOB_LOW_BG-8-test\0-1-\0-a/
+ var data = new Buffer([0,0x52,0x45,0x51,0,0,0,34,0,0,0,8,0x74,0x65,0x73,0x74,0,1,0,0x61]);
- test.deepEqual(packet.encode({ type: "SUBMIT_JOB_LOW_BG", name: "test", data: "a", encoding: "utf8" }), data);
+ test.deepEqual(packet.encode({ type: "SUBMIT_JOB_LOW_BG", name: "test", data: "a", encoding: "utf8", id: null }), data);
test.done();
};
exports["encode GET_STATUS"] = function (test) {
// \0REQ-GET_STATUS-5-test\0/
var data = new Buffer([0,0x52,0x45,0x51,0,0,0,15,0,0,0,4,0x74,0x65,0x73,0x74]);
- test.deepEqual(packet.encode({ type: "GET_STATUS", handle: "test" }), data);
+ test.deepEqual(packet.encode({ type: "GET_STATUS", handle: "test", id: null }), data);
test.done();
};

0 comments on commit 922205e

Please sign in to comment.