causztic
causztic

Reputation: 78

Undefined method "job_type" for main:Object with Whenever gem at scheduler.rb

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?

Upvotes: 0

Views: 748

Answers (1)

mpapis
mpapis

Reputation: 53158

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 ...

Upvotes: 0

Related Questions