mongodb-queue
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -19,13 +19,13 @@ /** | ||
} | ||
function date() { | ||
function now() { | ||
return (new Date()).toISOString() | ||
} | ||
function datePlus(date, s) { | ||
var delayDate = (new Date(date)).getTime() + s * 1000 | ||
return (new Date(delayDate)).toISOString() | ||
function nowPlusSecs(secs) { | ||
return (new Date(Date.now() + secs * 1000)).toISOString() | ||
} | ||
module.exports = function(mongoDbClient, name, opts) { | ||
var queue = new Queue(mongoDbClient, name, opts) | ||
return queue | ||
return new Queue(mongoDbClient, name, opts) | ||
} | ||
@@ -63,9 +63,4 @@ | ||
var self = this | ||
var aDate = date() | ||
var delayDate | ||
if ( self.delay ) { | ||
delayDate = datePlus(aDate, self.delay) | ||
} | ||
var msg = { | ||
visible : delayDate || aDate, | ||
visible : self.delay ? nowPlusSecs(self.delay) : now(), | ||
payload : payload, | ||
@@ -83,3 +78,3 @@ } | ||
var query = { | ||
visible : { $lt : date() }, | ||
visible : { $lt : now() }, | ||
deleted : { $exists : false }, | ||
@@ -94,3 +89,3 @@ } | ||
ack : id(), | ||
visible : (new Date(Date.now() + self.visibility * 1000)).toISOString(), | ||
visible : nowPlusSecs(self.visibility), | ||
} | ||
@@ -116,8 +111,9 @@ } | ||
var query = { | ||
ack : ack, | ||
visible : { $gt : date() }, | ||
ack : ack, | ||
visible : { $gt : now() }, | ||
deleted : { $exists : false }, | ||
} | ||
var update = { | ||
$set : { | ||
visible : (new Date(Date.now() + self.visibility * 1000)).toISOString(), | ||
visible : nowPlusSecs(self.visibility) | ||
} | ||
@@ -138,8 +134,9 @@ } | ||
var query = { | ||
ack : ack, | ||
visible : { $gt : date() }, | ||
ack : ack, | ||
visible : { $gt : now() }, | ||
deleted : { $exists : false }, | ||
} | ||
var update = { | ||
$set : { | ||
deleted : (new Date()).toISOString(), | ||
deleted : now(), | ||
} | ||
@@ -146,0 +143,0 @@ } |
{ | ||
"name": "mongodb-queue", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Message queues which uses MongoDB.", | ||
@@ -38,4 +38,3 @@ "main": "mongodb-queue.js", | ||
"mongodb", | ||
"queue", | ||
"" | ||
"queue" | ||
], | ||
@@ -42,0 +41,0 @@ "scripts": { |
@@ -163,4 +163,12 @@ # mongodb-queue # | ||
### 0.6.0 (not yet released) ### | ||
### 0.7.0 (2014-03-24) ### | ||
* [FIX] Fix .ping() so only visible/non-deleted messages can be pinged | ||
* [FIX] Fix .ack() so only visible/non-deleted messages can be pinged | ||
* [TEST] Add test to make sure messages can't be acked twice | ||
* [TEST] Add test to make sure an acked message can't be pinged | ||
* [INTERNAL] Slight function name changes, nicer date routines | ||
### 0.6.0 (2014-03-22) ### | ||
* [NEW] The msg.id is now returned on successful Queue.ping() and Queue.ack() calls | ||
@@ -167,0 +175,0 @@ * [NEW] Call quueue.ensureIndexes(callback) to create them |
@@ -53,3 +53,2 @@ var async = require('async') | ||
t.end() | ||
db.close() | ||
} | ||
@@ -59,2 +58,57 @@ ) | ||
test("single round trip, can't be acked again", function(t) { | ||
var queue = mongoDbQueue(db, 'default') | ||
var msg | ||
async.series( | ||
[ | ||
function(next) { | ||
queue.add('Hello, World!', function(err, id) { | ||
t.ok(!err, 'There is no error when adding a message.') | ||
t.ok(id, 'Received an id for this message') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
queue.get(function(err, thisMsg) { | ||
msg = thisMsg | ||
t.ok(msg.id, 'Got a msg.id') | ||
t.equal(typeof msg.id, 'string', 'msg.id is a string') | ||
t.ok(msg.ack, 'Got a msg.ack') | ||
t.equal(typeof msg.ack, 'string', 'msg.ack is a string') | ||
t.ok(msg.tries, 'Got a msg.tries') | ||
t.equal(typeof msg.tries, 'number', 'msg.tries is a number') | ||
t.equal(msg.tries, 1, 'msg.tries is currently one') | ||
t.equal(msg.payload, 'Hello, World!', 'Payload is correct') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
queue.ack(msg.ack, function(err, id) { | ||
t.ok(!err, 'No error when acking the message') | ||
t.ok(id, 'Received an id when acking this message') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
queue.ack(msg.ack, function(err, id) { | ||
t.ok(err, 'There is an error when acking the message again') | ||
t.ok(!id, 'No id received when trying to ack an already deleted message') | ||
next() | ||
}) | ||
}, | ||
], | ||
function(err) { | ||
t.ok(!err, 'No error during single round-trip when trying to double ack') | ||
t.end() | ||
} | ||
) | ||
}) | ||
test('db.close()', function(t) { | ||
t.pass('db.close()') | ||
db.close() | ||
t.end() | ||
}) | ||
}) |
@@ -51,3 +51,2 @@ var async = require('async') | ||
t.end() | ||
db.close() | ||
} | ||
@@ -57,2 +56,8 @@ ) | ||
test('db.close()', function(t) { | ||
t.pass('db.close()') | ||
db.close() | ||
t.end() | ||
}) | ||
}) |
@@ -64,3 +64,2 @@ var async = require('async') | ||
t.end() | ||
db.close() | ||
} | ||
@@ -70,2 +69,8 @@ ) | ||
test('db.close()', function(t) { | ||
t.pass('db.close()') | ||
db.close() | ||
t.end() | ||
}) | ||
}) |
@@ -60,3 +60,2 @@ var async = require('async') | ||
t.end() | ||
db.close() | ||
} | ||
@@ -66,2 +65,55 @@ ) | ||
test("ping: check that an acked message can't be pinged", function(t) { | ||
var queue = mongoDbQueue(db, 'ping', { visibility : 5 }) | ||
var msg | ||
async.series( | ||
[ | ||
function(next) { | ||
queue.add('Hello, World!', function(err, id) { | ||
t.ok(!err, 'There is no error when adding a message.') | ||
t.ok(id, 'There is an id returned when adding a message.') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
// get something now and it shouldn't be there | ||
queue.get(function(err, thisMsg) { | ||
msg = thisMsg | ||
t.ok(!err, 'No error when getting this message') | ||
t.ok(msg.id, 'Got this message id') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
// ack the message | ||
queue.ack(msg.ack, function(err, id) { | ||
t.ok(!err, 'No error when acking this message') | ||
t.ok(id, 'Received an id when acking this message') | ||
next() | ||
}) | ||
}, | ||
function(next) { | ||
// ping this message, even though it has been acked | ||
queue.ping(msg.ack, function(err, id) { | ||
t.ok(err, 'Error when pinging an acked message') | ||
t.ok(!id, 'Received no id when pinging an acked message') | ||
next() | ||
}) | ||
}, | ||
], | ||
function(err) { | ||
if (err) t.fail(err) | ||
t.pass('Finished test ok') | ||
t.end() | ||
} | ||
) | ||
}) | ||
test('db.close()', function(t) { | ||
t.pass('db.close()') | ||
db.close() | ||
t.end() | ||
}) | ||
}) |
@@ -109,3 +109,2 @@ var async = require('async') | ||
t.end() | ||
db.close() | ||
} | ||
@@ -115,2 +114,8 @@ ) | ||
test('db.close()', function(t) { | ||
t.pass('db.close()') | ||
db.close() | ||
t.end() | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30016
587
237