HabitRPG/habitrpg — pull request #2467 by colegleason (2014-01-18 08:57:07+00:00)
Title: Add script that let's you manually run cron form the command line

(This is a continuation of #2346.)

As mentioned in #2344, #2126.

To use:

node ./src/server.js --cron

You can also specify the current hour to run it manually for other users. `--cron-hour` is the hour in the server's timezone.

node ./src/server.js --cron --cron-hour 14

I think it may need a database migration to add user.cronTime. Not sure how defaults work and all that.

Once vetted, you would probably want this setup with [Heroku Scheduler](https://devcenter.heroku.com/articles/scheduler).

Other things to be done:
- [ ] Port all cron tests from habitrpg-shared over here.
- [ ] Remove the daysMissed check from user.fns.cron
- [ ] Remove api.cron from all routes.
- [ ] Setup heroku scheduler.
- [ ] ~~Do we want logging per-user? If so, instrument the code with that.~~ TODO later.
- [ ] Do we leave all 'checks' up to the query, or do we add extra sanity checks after user has ben fetched?
- [ ] Test with a large number of active users.
- [ ] Should we perhaps get an email with any errors encountered?

batchSize performance numbers on 4f95bbf.

| Users | batchSize | MB | Seconds |
| ------------- |--------------------| ------|--------------|
| 2238 | 2 | 172 | 25|
| 2238 | 5 | 171 |22 |
| 2238 | 10 | 193 |23 |
| 2238 | 100 | 321 | 24|
| 2238 | 1000 | 619 | 37|