【问题标题】:whenever/capistrano `method_missing_with_variables': undefined method `role_names_for_host'无论何时/capistrano `method_missing_with_variables':未定义的方法 `role_names_for_host'
【发布时间】:2013-01-22 09:06:33
【问题描述】:

在使用 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

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

Gem 版本

  • capistrano (2.8.0)
  • 无论何时 (0.8.2)

【问题讨论】:

  • 这个问题似乎出现在 0.8.2 版本,当我切换回 0.8.0 版本时,它又可以正常工作了。

标签: capistrano whenever whenever-capistrano


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-22
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 1970-01-01
    相关资源
    最近更新 更多