I am building a web app with node.js and mongodb. I need to add delayed jobs. For example, sending users an email one month after signing up. I haven't found an existing solution for delayed jobs besides Kue, but it uses Redis, and I would prefer to use my existing Mongodb before adding another resource to my web app.
Is there any existing solution for that?
The short answer is No. There is no port of Kue to MongoDB, nor there are any plans for such. There are no other open-source popular projects offering similar functionality at the moment.Moreover Redis seems like a better fit to this sort of project any-way.
While Kue is very interesting and offers much more than just delayed tasks, it seems your requirements are much simple.
If all you need is to send users an email one month after signing up, or that sort of thing, it is usually built into the OS level.
What I suggest you do, assuming you have a sendEmail
method (in general, that you figured out how the tasks would be done) is the following:
sendEmailHandler
a task to run once a day. In Windows this is done with "Scheduled Tasks"
, in OS X, BSD and Linux this is done using cron
. (cron tutorial). Most PaaS options also have this sort of option (Like nodejitsu, Azure...).MongoDB
which you choose to use, hold a collection of tasks,each with a 'start time'. An example for such tasks would be a specific user getting an email after 1 month.sendEmailHandler
script, check which tasks should run, and execute them, after which you should remove them from the MongoDB collection
.While this sounds like some work, it shouldn't take too long. All the code described here is very straightforward.
Kue lets you do stuff like priority, attempts, progress, etc which you do not need if I understand correctly. Working with a library that does many things to do something simple might end up biting you since degugging and maintenance are usually harder.
Good luck! Feel free to let me know if you'd like me to elaborate more on a specific part.
Another option is Agenda
Agenda is a light-weight job scheduling library for Node.js.
I was just researching the same thing and found this npm package:
monq - MongoDB-backed job queue for Node.js - https://www.npmjs.org/package/monq
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With