Am I right in thinking the most efficient way to run a background process every 2 hours on heroku (e.g. sending emails / stats collection etc.) is to use a cron, scheduled for every two hours, that then sticks items in a delayed_jobs queue (based on the dj gem) that is then picked up by a heroku worker instantly?
Further to that, once the app is in production, am I right in thinking the cost-effective approach would be to have hirefire spin up a worker to carry out the job and then shut it down afterwards?
Are there other approaches I should consider? I have not done this kind of delayed job work before – in development and in basic production testing before go live I have it all based on a heroku cron – but in production that doesn’t seem sensible if the load on the cron job increases.
Any pointers on worthwhile alternative approaches appreciated!
Hirefire is definitely the way to go if you don’t have a full time set of work for a worker to do as you’ll be paying for a dormant worker otherwise.
Another option for the timing is to get the delayed job to reschedule itself when it completes using the :run_at argument that’s available. The worker will then do it when it’s hit the time (although I’ve never tested this would work with Hirefire as I think they just look at Job count)
It’s a pretty sound approach overall, and what I would use.