I have a Rails app deployed on Heroku with the Heroku scheduler add-on successfully working for daily jobs.
Now I want a weekly job, but the scheduler add-on does not allow me a weekly option.
Any suggestions on how I could accomplish this:
Using the DashboardNavigate to the “Resources” tab of the app's Dashboard. Search for “Heroku Scheduler” in the Add-ons search box. Follow the prompts to provision the Add-on.
Reliable delivery Heroku Scheduler is a free add-on, but it doesn't guarantee that jobs will be executed at their scheduled time, or at all for that matter. While it is rare, the possibility that a job may be skipped or run twice does exist.
Click on the Heroku Scheduler Add-on from the Resources tab on the Dashboard or run the command heroku addons:open scheduler from the CLI. Click edit on your scheduled job (usually indicated with a pencil). Under Run Command, look for a dropdown that allows you to select the dyno plan. Save Job.
One approach would be the one of your 2nd bullet point:
activate the Heroku cron add-on, and add a cron.rake
task in app/lib/tasks
Activate the Heroku scheduler add-on, and add a scheduler.rake
task in app/lib/tasks
task :your_weekly_task=> :environment do if Time.now.friday? # previous answer: Date.today.wday == 5 #do something end end
You even have the luxury of defining the day you want your task to run ;o) (5 is for Friday)
EDIT: by the way, Cron is deprecated and Heroku recommends switching to their Scheduler add-on. This doesn't change the approach for a weekly job though.
EDIT2: adjustments to my answer based on feedback from sunkencity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With