Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Lightweight job scheduling for Node.js (github.com/rschmukler)
37 points by rschmukler on Nov 1, 2013 | hide | past | favorite | 15 comments



I am working on a scheduled reminder (email/SMS service) to send notifications. I've been looking for a scheduling/Cron service for node. There are few I am evaluating. I will consider yours. If I reboot the machine or node server, will it automatically queue up the jobs?


So if you reboot the server, you just need to make sure that you call agenda.start() again. This will start the job processor which looks for jobs that have come due in the database and process them. agenda.every('3 minutes', 'job name') is a special case in which it will only schedule that job once (because if you think about it, otherwise every time you ran that line you'd get a new job... This makes it so you can define it in the same file as where you call agenda.start() and not end up defining new versions of those repeating jobs every time the file gets ran). Hope this makes sense/helps.


If you wanted even more flexible schedules, you might want to look into Later.js (http://bunkat.github.io/later/), a small library I created just for this purpose. It supports composite and exception schedules, cron schedules, and lots of different time periods. Everything can be specified using an API or using English text.

I also built replacements for setTimeout and setInterval to use Later schedules, so it should be easy enough to plug it into your solution.


Very cool. How robust is the english parsing? For example, would it understand something like "The first wednesday of every month"? Either way I will definitely check it out.


You can see the grammar and lots of examples at http://bunkat.github.io/later/parsers.html#text. For your question, it would be 'on Wednesday on the first day instance every 1 month' or 'on the first day instance on Wed' would also work.


Curious, why the choice of mongo vs something like redis?


I thought the same. For redis there's Kue, which looks a lot more feature complete.

https://github.com/learnboost/kue


See above for Mongo vs Redis. As for "feature completeness", this is a pretty feature complete job scheduling library. It leaves the writing of a Web interface to someone else, but for scheduling jobs it gets the job done. (Haha, that pun was irresistible)


The choice of Mongo vs Redis was intentional. Without configuration Redis doesn't guarantee persistence as well as Mongo. Since Redis is often used for non-critical data such as sessions I didn't want to enforce sacrificing performance of sessions for persistence.


Looking at these scheduling modules, I wonder to myself why saving a .json file wouldn't be more simple. Filesystem cache, available to all workers on the system and no dependencies required.

I mean, if you're worried about cluster workers file reading being slower than a db connection, the json store could be write-only most of the time and only read on app startup while schedules are synced over cluster messaging.


In my mind there are a few reasons, but indeed it could definitely be implemented with a flat file. Sometimes you aren't guaranteed write-access to a file on the system, especially if you're using a PAAS like Heroku. That also complicates things if you want to build something to view/edit the data in an isolated instance. These are just the reasons that come to the top of my head, but in reality you're right, this could be finessed to be done with just a flat file.


Good points. Perhaps structuring it in a way to allow for a flat file or redis/nosql/sql might push a particular schedule module into greater favor, at least for those of us who want our apps to consist of minimal different db methods.


Any word on how this affects battery life, specifically on Macs? I've had to turn on atrun on my MacBook Air and it has absolutely destroyed my battery life.


I haven't tested on a laptop be honest. Interesting point. What is atrun? I'll do some research and see if I can do anything about it... For reference node idles at about 3% CPU on my dev-box.


This is perfect. Thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: