Reputation: 1323
I have a Rails app I'm running on Heroku.
I'd like to, every midnight, run a few queries on my database (I could do it with ActiveRecord or SQL, not fussy), do some light processing of the results, and send a formatted email with the data (either inline or attached CSV).
What's the best way to do this? Locally I could just schedule a cron job to run a script, with Heroku I'm not sure. I read that heroku has a cron add-on, but couldn't find it, and I'm not sure what functionality is available there anyways. Can I just do a headless attach to a rails console and get the output? Can I do this as a rake task?
Any information would be appreciated.
Upvotes: 1
Views: 362
Reputation: 10856
The [Heroku Scheduler addon] mentioned is a good way to do the scheduling.
class Report
def self.generate_and_send
# Your logic here
end
end
# To run task in Terminal
$ heroku run rails runner Report.generate_and_send
# What to schedule on Heroku Scheduler
rails runner Report.generate_and_send
Upvotes: 3