未定义的方法“job_type”for main:每当gem处于scheduler.rb时的对象

问题描述:

我一直试图实现每当gem来帮助安排我的Sidekiq任务。我检查了crontab并且它已正确更新,并且bundle exec只要在终端中正常工作。未定义的方法“job_type”for main:每当gem处于scheduler.rb时的对象

这里是我的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 

在crontab如下所示:

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

然而,cron作业被调用时,返回此错误:

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

我也尝试通过终端手动运行cron作业,并注意到rvm也正确切换。我也试着设置

env "GEM_HOME", ENV["GEM_HOME"] 

但错误只是代替改为/path/to/app/config/schedule.rb:2:in <top (required)>': undefined method ENV”主:对象(NoMethodError)

有什么建议吗?

使用包装:https://rvm.io/integration/cron/#direct

你可以创造更多的包装:

rvm wrapper create [email protected] my-project bundle 

,然后用它喜欢:

/path/to/rvm/bin/my-project_bundle ... 
+0

这个方法我试过为好,不能正常工作。我决定将我的计划任务的运行方式改为发条,不过谢谢! – causztic 2013-03-27 02:19:37