Skip to content

Commit

Permalink
Merge pull request #13 from reedsy/sort-visible
Browse files Browse the repository at this point in the history
⚡️ Sort `get()` by `visible`
  • Loading branch information
alecgibson authored Oct 23, 2024
2 parents 29681c1 + c44f974 commit 8d04c21
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
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,
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

0 comments on commit 8d04c21

Please sign in to comment.