0

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?

stevec
  • 41,291
  • 27
  • 223
  • 311

2 Answers2

1

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.

ollaollu
  • 473
  • 7
  • 19
0

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.

stevec
  • 41,291
  • 27
  • 223
  • 311