Skip to content

Commit 8d04c21

Browse files
authored
Merge pull request #13 from reedsy/sort-visible
⚡️ Sort `get()` by `visible`
2 parents 29681c1 + c44f974 commit 8d04c21

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

mongodb-queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class MongoDBQueue<T = any> {
130130
visible: {$lte: now()},
131131
};
132132
const sort: Sort = {
133-
_id: 1,
133+
visible: 1,
134134
};
135135
const update: UpdateFilter<Message<T>> = {
136136
$inc: {tries: 1},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reedsy/mongodb-queue",
3-
"version": "7.0.0",
3+
"version": "7.0.1",
44
"description": "Message queues which uses MongoDB.",
55
"main": "mongodb-queue.js",
66
"scripts": {

test/dead-queue.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,6 @@ setup().then(({client, db}) => {
4040
t.end();
4141
});
4242

43-
test('two messages, with first going over 3 tries', async function(t) {
44-
const deadQueue = new MongoDBQueue(db, 'dead-queue-2');
45-
const queue = new MongoDBQueue(db, 'queue-2', {visibility: 1, deadQueue: deadQueue, maxRetries: 3});
46-
let msg;
47-
48-
const origId = await queue.add('Hello, World!');
49-
t.ok(origId, 'Received an id for this message');
50-
const origId2 = await queue.add('Part II');
51-
t.ok(origId2, 'Received an id for this message');
52-
53-
for (let i = 1; i <= 3; i++) {
54-
msg = await queue.get();
55-
t.equal(msg.id, origId, 'We return the first message on first go');
56-
await new Promise((resolve) => setTimeout(function() {
57-
t.pass(`Expiration #${i}`);
58-
resolve();
59-
}, 2 * 1000));
60-
}
61-
62-
msg = await queue.get();
63-
t.equal(msg.id, origId2, 'Got the ID of the 2nd message');
64-
t.equal(msg.payload, 'Part II', 'Got the same payload as the 2nd message');
65-
66-
msg = await deadQueue.get();
67-
t.ok(msg.id, 'Got a message id from the deadQueue');
68-
t.equal(msg.payload.id, origId, 'Got the same message id as the original message');
69-
t.equal(msg.payload.payload, 'Hello, World!', 'Got the same as the original message');
70-
t.equal(msg.payload.tries, 4, 'Got the tries as 4');
71-
t.end();
72-
});
73-
7443
test('client.close()', function(t) {
7544
t.pass('client.close()');
7645
client.close();

0 commit comments

Comments
 (0)