2

在使用 capistrano 部署时,我正在使用when/capistrano 来更新我的 cron_tab,直到最近我的部署在更新 cron_tab 时开始失败。

.rvm/gems/ruby-1.9.3-p362-turbo@psg-web/gems/capistrano-2.8.0/lib/capistrano/configuration/variables.rb:122:in `method_missing_with_variables': undefined method `role_names_for_host' for #<Capistrano::Configuration:0x000000018e6a10> (NoMethodError)

我正在设置 *role_names_for_host*

set_default(:whenever_roles, [:workers])

我的任务看起来像这样

namespace :whenever do
  desc "Stop whenever"
  task :stop , roles: [:workers] do
    clear_crontab
  end

  desc "Start whenever"
  task :start , roles: [:workers] do
    update_crontab
  end

  desc "Restart whenever"
  task :restart , roles: [:workers] do
    update_crontab
  end

  after 'deploy:symlink', 'whenever:update_crontab'
  %w[start stop restart].each do |command|
    after "deploy:#{command}", "whenever:#{command}"
  end
end

关于我可能做错的任何想法?

宝石版本

  • 卡皮斯特拉诺 (2.8.0)
  • 每当(0.8.2)
4

1 回答 1

1

在 capistrano 2.9.0 之后引入了缺少的方法。

补丁:您可以将其添加到 Capfile 或 deploy.rb 文件的顶部:

require 'capistrano/server_definition'
require 'capistrano/role'
class Capistrano::Configuration
  def role_names_for_host(host)
    roles.map {|role_name, role| role_name if role.include?(host) }.compact || []
  end
end

我建议每当更新它的 gem 依赖项时:)

(来源:https ://github.com/javan/whenever/issues/302#issuecomment-14962350 )

于 2013-03-15T14:09:01.600 回答