Read more

whenever: Make runner commands use bundle exec

Henning Koch
June 28, 2014Software engineer at makandra GmbH

This is fixed in modern whenever versions.

In whenever Show archive.org snapshot you can schedule Ruby code directly like so:

every 1.day, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Combined with the best practice to hide background tasks behind a single static methods you can test, this is probably preferable to defining additional Rake tasks.

Unfortunately when whenever register a runner command, it doesn't use bundle exec in the resulting crontab. This gets you errors like this:

`gem_original_require': no such file to load -- bundler/setup (LoadError)

You can work around this by putting this on the top of your config/schedule.rb:

job_type :runner, "cd :path && bundle exec rails runner -e :environment ':task' :output"
Posted by Henning Koch to makandra dev (2014-06-28 16:58)