Gerard
Gerard

Reputation: 4848

Cron Jobs on Heroku

According to the Heroku docs:

Cron jobs execute based on when you enable the add-on

However, I enabled the cron add on at 8pm two nights ago and the cron job did not run at 8pm last night. At 3pm today, I ran "heroku cron" and the job kicked off without any issue.

Does anyone have any experience with this? Does running "heroku cron" mean it will run at 3pm every day from now on? I am using the daily cron job add on and not the hourly addon.

Thanks, gearoid.

Upvotes: 2

Views: 3510

Answers (2)

Justin Thiele
Justin Thiele

Reputation: 476

You can see when your cron job is scheduled by looking at your app's Cron add-on on the web interface.

The Heroku Backup Task gem makes it really easy automatically back up with a cron job.

Heroku's native automatic backups add-on is in private beta now, so hopefully it'll be released soon: http://devcenter.heroku.com/articles/pgbackups

Upvotes: 5

Sam 山
Sam 山

Reputation: 42865

You do not need an addon to run chronic tasks on Heroku.

Install the gem

 gem install rufus-scheduler

Make sure you include the gem in bundler or however you are including it.

Then you need to create a file called task_scheduler.rb and stick this in you initializers directory.

 require 'rufus/scheduler'
 scheduler = Rufus::Scheduler.start_new

 scheduler.every '1s' do

      puts "Test!"      
      #do something here

 end

If you have any trouble you can see this blog post:

http://intridea.com/2009/2/13/dead-simple-task-scheduling-in-rails?blog=company

Upvotes: 4

Related Questions