stevec
stevec

Reputation: 52797

How to run rails rake task more frequently than 10 minutes on heroku?

There's a straight forward explanation of why cron jobs and tasked scheduled with whenever gem won't work on heroku

Is there any way to schedule a rake task to run more frequently than every 10 minutes (the minimum frequency heroku scheduler offers), for example every 1 minute?

Upvotes: 0

Views: 819

Answers (2)

stevec
stevec

Reputation: 52797

I think @ollaollu's method is probably superior, but for future reference what worked for me was to use a Procfile to run an infinite loop on boot, and that effectively runs a process every 5 seconds and even works after heroku restart.

Upvotes: 0

ollaollu
ollaollu

Reputation: 483

You can use a combination of Clockwork gem and Heroku Procfile.

  • in your lib/clock.rb, you can do something like:
every(1.minute, 'Run task') do
  Rake::Task['namespace:task'].invoke
end
  • then add clock: bundle exec clockwork lib/clock.rb to your Heroku Procfile

Clockwork supports a lot of time variations.

Upvotes: 1

Related Questions