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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)