4

According to whenever documentation is possible to specify a set of whenever_roles (https://github.com/javan/whenever#capistrano-roles). Now I want to define a set of cronjobs in the schedule.rb and divide them based on their roles something like the following:

set :output, "log/cron.log"

every :day, at: '11:00', roles: :whenever_alt do
  runner 'MySuperScriptClass1.start'
end

every :day, at: '12:30', roles: :whenever_main do
  runner 'MySuperScriptClass2.start'
end

And the deploy file

set :whenever_roles, ["whenever_main", "whenever_alt"]

On production.rb

role :whenever_main,  %w{ip_address_1}
role :whenever_alt,   %w{ip_address_2}

The problem is that when I deploy capistrano using that configuration I get

cap aborted!
undefined method `to_sym' for [:whenever_main, :whenever_alt]:Array
/Users/.../gems/capistrano-
3.0.1/lib/capistrano/configuration/servers/role_filter.rb:25:in `each'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers/role_filter.rb:25:in
 `flat_map'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers/role_filter.rb:25:in
 `required'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers/role_filter.rb:15:in
 `roles'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers/role_filter.rb:11:in
 `for'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers.rb:45:in    
 `fetch_roles'
  /Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration/servers.rb:18:in
  `roles_for'
/Users/.../gems/capistrano-3.0.1/lib/capistrano/configuration.rb:45:in `roles_for'

/Users/.../gems/capistrano-3.0.1/lib/capistrano/dsl/env.rb:43:in `roles'
/Users/.../gems/whenever-0.9.0/lib/whenever/tasks/whenever.rake:4:in `block (2 levels) in <top (required)>'

How can I separate cronjobs one on each server using whenever?

Thanks a lot

Pablo
  • 3,433
  • 7
  • 44
  • 62

1 Answers1

5

1) In your schedule.rb, make the roles into arrays

every :day, at: '11:00', roles: [:whenever_alt] do # NOTE that ":whenever_alt" is now "[:whenever_alt]"
  runner 'MySuperScriptClass1.start'
end

every :day, at: '12:30', roles: [:whenever_main] do
  runner 'MySuperScriptClass2.start'
end

2) Make sure you version of whenever is at least 0.9.1

Isaac Betesh
  • 2,935
  • 28
  • 37