Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good alternative to Kue that works with MongoDB instead of Redis?

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?

like image 225
Ita Avatar asked Mar 23 '13 14:03

Ita


3 Answers

The short answer

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.

The long answer

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:

  1. Depending on the operating system, schedule 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...).
  2. That tasks should be a node.js script that iterates through a list of long running tasks (that is, stuff that runs once a month, a week, or longer).
  3. In 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.
  4. In your 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.

like image 119
Benjamin Gruenbaum Avatar answered Nov 04 '22 15:11

Benjamin Gruenbaum


Another option is Agenda

Agenda is a light-weight job scheduling library for Node.js.

like image 7
Tamlyn Avatar answered Nov 04 '22 15:11

Tamlyn


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

like image 3
mc matt g Avatar answered Nov 04 '22 16:11

mc matt g