From 74ee329226136f8e2b376ba6fc9958c829e1dc0d Mon Sep 17 00:00:00 2001 From: Nauman Ramzan Date: Thu, 28 Jun 2018 22:43:06 +0400 Subject: [PATCH] Added makeTaskId function --- index.coffee | 7 +++++-- index.js | 10 +++++++++- package-lock.json | 6 ++++++ package.json | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/index.coffee b/index.coffee index b275ecd..859eaed 100644 --- a/index.coffee +++ b/index.coffee @@ -42,10 +42,12 @@ class RedisSMQ extends EventEmitter port: 6379 options: {} client: null - ns: "rsmq" + ns: "rsmq", + makeTaskId: (uuid) => uuid, , options @redisns = opts.ns + ":" + @makeTaskId = opts.makeTaskId if opts.client?.constructor?.name is "RedisClient" @redis = opts.client else @@ -485,7 +487,8 @@ class RedisSMQ extends EventEmitter if q.maxsize isnt -1 and options.message.length > q.maxsize @_handleError(cb, "messageTooLong") return - + # Makr final task id + q.uid = @makeTaskId(q.uid, options.message) # Ready to store the message mc = [ ["zadd", "#{@redisns}#{options.qname}", q.ts + options.delay * 1000, q.uid] diff --git a/index.js b/index.js index d849b98..2e7d0be 100644 --- a/index.js +++ b/index.js @@ -58,9 +58,15 @@ RedisSMQ = (function(superClass) { port: 6379, options: {}, client: null, - ns: "rsmq" + ns: "rsmq", + makeTaskId: (function(_this) { + return function(uuid) { + return uuid; + }; + })(this) }, options); this.redisns = opts.ns + ":"; + this.makeTaskId = opts.makeTaskId; if (((ref = opts.client) != null ? (ref1 = ref.constructor) != null ? ref1.name : void 0 : void 0) === "RedisClient") { this.redis = opts.client; } else { @@ -430,6 +436,8 @@ RedisSMQ = (function(superClass) { _this._handleError(cb, "messageTooLong"); return; } + q.uid = _this.makeTaskId(q.uid, options.message); + console.log(q.uid); mc = [["zadd", "" + _this.redisns + options.qname, q.ts + options.delay * 1000, q.uid], ["hset", "" + _this.redisns + options.qname + ":Q", q.uid, options.message], ["hincrby", "" + _this.redisns + options.qname + ":Q", "totalsent", 1]]; _this.redis.multi(mc).exec(function(err, resp) { if (err) { diff --git a/package-lock.json b/package-lock.json index 5bb83d5..889d5b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,12 @@ "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", "dev": true }, + "coffee-script": { + "version": "1.12.7", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz", + "integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==", + "dev": true + }, "commander": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", diff --git a/package.json b/package.json index 4b8a5b4..6158864 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ }, "scripts": { "build": "coffee -cb index.coffee test/test.coffee", - "test": "mocha ./test/test.js" + "test": "mocha ./test/test.js", + "pretest": "npm run build" }, "dependencies": { "@types/redis": "^2.8.0",