main的未定义方法“job_type”:具有Whenever在scheduler.rb的对象

时间:2013-03-26 06:40:21

标签: ruby-on-rails rvm capistrano crontab whenever

我一直在尝试实施Whenever gem以帮助安排我的Sidekiq任务。我检查了crontab并且它已正确更新,并且捆绑exec,只要在终端中正常工作。

这是我的日程表.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&#39; 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&#39; for main:Object(NoMethodError)

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

您可以使用以下命令创建更多包装:

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

然后使用它:

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