0

I have been trying to implement the Whenever gem to help schedule my Sidekiq tasks. I checked the crontab and it was updated correctly, and bundle exec whenever works correctly in the terminal as well.

Here is my schedule.rb:

# set RAILS_ROOT  
RAILS_ROOT = File.dirname(__FILE__) + '/..'  

set :output, 'log/whenever.log'
set :job_template, "bash -l -i -c ':job'"
job_type :runner, "cd :path && bundle exec rails runner -e staging ':task' :output"

every 1.day, :at => '10:30 pm', :roles => [:app] do
  runner "Backup.perform_async"
end

The crontab is shown below:

bash -l -i -c 'cd /path/to/app && bundle exec rails runner -e staging '\''Backup.perform_async'\'' >> log/whenever.log 2>&1'

However, when the cron job is called, this error was returned:

/path/to/app/config/schedule.rb:8:in <top (required)>': undefined methodjob_type' for main:Object (NoMethodError)

I also tried to manually run the cron job via the terminal and noticed that rvm switched correctly as well. I have also tried setting

env "GEM_HOME", ENV["GEM_HOME"]

but the error just instead changed to /path/to/app/config/schedule.rb:2:in <top (required)>': undefined methodenv' for main:Object (NoMethodError)

Any ideas?

causztic
  • 78
  • 9

1 Answers1

0

Use wrappers: https://rvm.io/integration/cron/#direct

You can create more wrappers with:

rvm wrapper create 1.9.3@my-project my-project bundle

And then use it like:

/path/to/rvm/bin/my-project_bundle ...
mpapis
  • 52,729
  • 14
  • 121
  • 158
  • I tried this method as well, wasn't working. I decided to change my approach of running scheduled tasks to clockwork instead, thanks though! – causztic Mar 27 '13 at 02:19