How can I get the heroku scheduler to run weekly?
Is this even possible, from what I can see I can only schedule hourly, every 10 mins, or daily tasks with no option for a weekly.
If not, what are other Heroku Add-ons that might allow me to run jobs (i.e. cron job) tasks on a weekly bassis in production.
Thanks!
Update 2:
require 'date'
task :weeklydelete do
if Date.today.wday.zero?
runner "Event.clear_expired"
runner "Activity.clear_expired"
end
end
Update 2.5:
$heroku run bundle exec rake weeklydelete -a friendiosenew
Running `bundle exec rake weeklydelete` attached to terminal... up, run.6194
rake aborted!
undefined local variable or method `path' for main:Object
/app/lib/tasks/weeklydelete.rake:2:in `block in <top (required)>'
Tasks: TOP => weeklydelete
(See full trace by running task with --trace)
I found a great answer here. Just use a bash script in the Heroku Scheduler that checks the day of the week before running your command:
if [ "$(date +%u)" = 1 ]; then MY_COMMAND; fi # only run on Mondays
Set up a daily job, and in the job check if the day of week is Sunday (or whichever day). If it is that day, run the job. If it isn't that day, do nothing and exit.
edit: I was thinking more like
require 'date'
task :weeklydelete do
if Date.today.wday.zero?
runner "Event.clear_expired"
runner "Activity.clear_expired"
end
end
The logging to a file stuff wont work on heroku, and I'm not sure what you're using for the time stuff, but I fear if scheduler runs it not exactly at 3, that stuff might not work.
the Date class has some really great helper methods. So, Date.today.wday.zero?
could be shortened to Date.today.sunday?
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