whenever: Make runner commands use bundle exec

Updated . Posted . Visible to the public. Deprecated.

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

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"
Henning Koch
Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2014-06-28 14:58)