5

I'm wondering what the best way is to setup a clock process on Heroku. My app is built entirely in Node and I was planning on using node-schedule to specify my schedules.

My question is: should the clock process itself trigger the events in my cron process and run them within it's own allocated dyno? Heroku seems to indicate that you should use a worker to handle this. In that case, I'm wondering how I can get my clock process to tell the worker to run a specific procedure?

I've been reading up on the Python method to do this and it seems like they are simply triggering the process within the same dyno.

Thanks.

ddibiase
  • 1,412
  • 1
  • 20
  • 44

1 Answers1

2

Heroku says clock processes should trigger a new dyno, which makes sense for scalability since you could turn your frequency up to 11 and break the clock process. https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes

I would use https://github.com/toots/node-heroku to kick off new processes in separate one-time dynos. But, if you want to have a pool of workers that process clock processes, than you'll need a queue like Resque or Kue. The clock process will enqueue new tasks and the worker process(es) will dequeue them.

Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
  • This seems like a lot of effort. I'm simply triggering a process every hour and one at midnight. Is there a way to use the Schedular app they provide and tell it to work within a separate dyno? – ddibiase Jul 28 '13 at 21:51
  • lol correction: didn't mean it's a lot of work. it just seems like overkill for my needs. Do you think I could run a clock/worker process and manually trigger the schedules as I please? – ddibiase Jul 28 '13 at 21:58
  • 1
    We're perfectly happy with the free Heroku scheduler addon that enables a `run node send_emails.js` every hour or every day. https://addons.heroku.com/scheduler – Dan Kohn Jul 29 '13 at 01:58
  • @dankohn I'm adding the task in scheduler as `run node my_task.js` but getting an error in production of command run not found? Do you happen to know the syntax for adding in scheduler? – OliverJ90 Sep 15 '15 at 14:18
  • 2
    @OliverJ90 a bit late answer, but for future readers, the task should be added without `run`, e.g. `node my_task.js`, or perhaps `npm run something`. – Adam Reis Dec 07 '16 at 18:11