Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongodb-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class MongoDBQueue<T = any> {
visible: {$lte: now()},
};
const sort: Sort = {
_id: 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we would have to change our index for it to work best

this.col.createIndex({deleted: 1, visible: 1}),

to

this.col.createIndex({visible: 1, deleted: 1}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it it belongs to this PR though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a different change, which will need an index regeneration.

I'm also not sure it's needed, since I think in theory MongoDB can still leverage the index for a non-prefix sort since deleted: {$exists: false} counts as an equality condition.

visible: 1,
};
const update: UpdateFilter<Message<T>> = {
$inc: {tries: 1},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reedsy/mongodb-queue",
"version": "7.0.0",
"version": "7.0.1",
"description": "Message queues which uses MongoDB.",
"main": "mongodb-queue.js",
"scripts": {
Expand Down
31 changes: 0 additions & 31 deletions test/dead-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,6 @@ setup().then(({client, db}) => {
t.end();
});

test('two messages, with first going over 3 tries', async function(t) {
const deadQueue = new MongoDBQueue(db, 'dead-queue-2');
const queue = new MongoDBQueue(db, 'queue-2', {visibility: 1, deadQueue: deadQueue, maxRetries: 3});
let msg;

const origId = await queue.add('Hello, World!');
t.ok(origId, 'Received an id for this message');
const origId2 = await queue.add('Part II');
t.ok(origId2, 'Received an id for this message');

for (let i = 1; i <= 3; i++) {
msg = await queue.get();
t.equal(msg.id, origId, 'We return the first message on first go');
await new Promise((resolve) => setTimeout(function() {
t.pass(`Expiration #${i}`);
resolve();
}, 2 * 1000));
}

msg = await queue.get();
t.equal(msg.id, origId2, 'Got the ID of the 2nd message');
t.equal(msg.payload, 'Part II', 'Got the same payload as the 2nd message');

msg = await deadQueue.get();
t.ok(msg.id, 'Got a message id from the deadQueue');
t.equal(msg.payload.id, origId, 'Got the same message id as the original message');
t.equal(msg.payload.payload, 'Hello, World!', 'Got the same as the original message');
t.equal(msg.payload.tries, 4, 'Got the tries as 4');
t.end();
});

test('client.close()', function(t) {
t.pass('client.close()');
client.close();
Expand Down