Comments (6)
It doesn't do long polling currently, since I don't think MongoDB does long polling - and since we're dependent on that, this would be impossible.
I guess the best way to do this would be just 'poll' (rather than 'long poll') and the library could poll for you. e.g. every 5 seconds (opts.interval
), for a maximum of 10 times (opts.maxtimes
) or something like that.
I'd leave .get(opts, callback)
as it was and perhaps add a .poll(opts, callback)
. Then .poll()
could easily just call .get()
internally and could also take the same opts.visibility
option too which it also just passes on. How does that sound?
I'm not promising I'm going to implement it, though I think it's a good idea. Feel free to send a PR if you're keen. :)
from mongodb-queue.
I think you could implement long polling by storing the callback internally inside the mongodb-queue instance when the .get
method is called. When .add
is called later on, then the callback gets called (if it exists).
I haven't really looked at your code yet. I might try implementing it at some point.
from mongodb-queue.
This won't work (in general) since you could be using the MongoDB queue collection from any number of services. ie. your web service might be adding messages to the queue, and a background worker might be taking them off, therefore your suggestion here won't really work. (It won't really harm it either, but it won't do what you're expecting it to.)
Even if it was added like this, there should definitely be an upper limit amount of time to wait before returning undefined
. You wouldn't want to wait forever.
from mongodb-queue.
Oh I see what you mean. I'm working on an email service and I was planning on using this queue for sending emails and retrying failed attempts. All of this happens on a server within a single Node process.
So this might be a very specific use case I guess? I think this feature would be useful if you're only planning on using this queue from a single service.
from mongodb-queue.
I think .poll()
would be useful in general, however .longpoll()
or the implementation you mentioned in two comment above (three comments ago) wouldn't be.
Anyway, feel free to close if you like. I may have a crack at .poll()
sometime, or I may not. :)
from mongodb-queue.
I'm trying to use this polling function:
var q = mongoDbQueue(db, 'queue')
var handler = (err, id) => err ? console.error(err) : null
var poll
poll = (cb) => {
q.get( (err, msg) => {
if( err || !msg ) return setTimeout( () => poll(cb), 500 )
msg.payload = JSON.parse(msg.payload)
cb(err, msg, function(){
q.ack(msg.ack, handler)
q.clean(handler) // cleanup
poll(cb) // get next message
})
})
}
q.poll = poll
q.poll( function(err,msg,next){
// process message
next()
})
It's probably not perfect, but we'll see
from mongodb-queue.
Related Issues (18)
- get() method doesn't follow the FIFO HOT 10
- Incorrect indexes? HOT 8
- findOneAndUpdate vs findAndModify HOT 6
- Date type instead of string for datetime fields HOT 2
- Cant connect HOT 4
- Dead Queues Management HOT 1
- concurrency? HOT 4
- for await...of as interface for queue consumer
- How can i connect this with mongoose? HOT 2
- returnOriginal flag is deprecated in findOneAndUpdate
- Batch Processing
- message order after visibility timeout HOT 4
- Using mongdb nodejs driver 4 HOT 2
- Error acknowledging a queue: Queue.ack(): Unidentified ack HOT 3
- Support for node-mongodb-native2 HOT 3
- Support MongoDB 3.x HOT 3
- awesome package, how to work on all queued messages effectively? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongodb-queue.