whenever/capistrano `method_missing_with_variables': undefined method `role_names_for_host'

1.7k Views Asked by At

I'm using whenever/capistrano to update my cron_tab when deploying with capistrano, it was working great until recently my deploys started to fail when updating the 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)

I am setting the *role_names_for_host*

set_default(:whenever_roles, [:workers])

and my tasks look like this

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

Any Ideas on what I could be doing wrong?

Gem versions

  • capistrano (2.8.0)
  • whenever (0.8.2)
1

There are 1 best solutions below

0
On

The method missing is introduced in capistrano after 2.9.0.

Patch: You can add this at the top of your Capfile or deploy.rb file:

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

I would recommend whenever updating it's gem dependencies :)

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