forked from chilts/mongodb-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Add reEnqueue() functionality to exposed API
#22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c03c43a
exposed method, tested, bumped minor version
dodoarg aa9a563
++ readme doc for new method
dodoarg 1f9e35f
internal refactor --> updateByAck
dodoarg 475c470
copilot was concerned
dodoarg 7d9476d
didn't like passing a method name just to format some error msg
dodoarg 6e5c2dc
minor tweak to readme msg
dodoarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| const test = require('tape'); | ||
|
|
||
| const setup = require('./setup.js'); | ||
| const {MongoDBQueue} = require('../'); | ||
|
|
||
| setup().then(({client, db}) => { | ||
| test('re-enqueue: message becomes immediately available again, with tries and ack reset', async function(t) { | ||
| const queue = new MongoDBQueue(db, 're-enqueue', {visibility: 30}); | ||
|
|
||
| const id = await queue.add('Hello, World!'); | ||
| const msg = await queue.get(); | ||
|
|
||
| const reEnqueuedId = await queue.reEnqueue(msg.ack); | ||
| t.equal(reEnqueuedId, id, 'Re-enqueue keeps the same document id'); | ||
|
|
||
| const requeued = await queue.get(); | ||
| t.ok(requeued, 'Message is immediately available again'); | ||
| t.equal(requeued.id, id, 'Same document id after re-enqueue'); | ||
| t.equal(requeued.tries, 1, 'Tries restarted from zero'); | ||
| t.notEqual(requeued.ack, msg.ack, 'The old ack no longer applies'); | ||
| // ack so it doesn't linger reserved and leak into the next test on this collection | ||
| await queue.ack(requeued.ack); | ||
|
|
||
| t.end(); | ||
| }); | ||
|
|
||
| test("re-enqueue: can't re-enqueue with a stale or unknown ack", async function(t) { | ||
| const queue = new MongoDBQueue(db, 're-enqueue', {visibility: 30}); | ||
|
|
||
| await queue.add('Hello, World!'); | ||
| const msg = await queue.get(); | ||
| await queue.ack(msg.ack); | ||
|
|
||
| const error = await queue.reEnqueue(msg.ack).catch((err) => err); | ||
| t.ok(error, 'Got an error when re-enqueuing an already-acked message'); | ||
|
|
||
| const unknownError = await queue.reEnqueue('unknown-ack').catch((err) => err); | ||
| t.ok(unknownError, 'Got an error when re-enqueuing an unknown ack'); | ||
|
|
||
| t.end(); | ||
| }); | ||
|
|
||
| test('client.close()', function(t) { | ||
| t.pass('client.close()'); | ||
| client.close(); | ||
| t.end(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.