2014-02-24 35 views
2

根據何時可以指定一組文檔every_roles(https://github.com/javan/whenever#capistrano-roles)。現在我想根據自己的角色類似下面的schedule.rb定義一組cronjobs和它們劃分:每當gem指定在哪個服務器上運行每個作業時

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 

而且部署文件

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

在production.rb

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

的問題是,當我使用該配置Capistrano的部署我得到

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)>' 

如何在每臺服務器上分別使用cronjobs一次?

非常感謝

回答

3

1)在你的schedule.rb,使角色進入陣列

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)確保你的,只要是至少0.9.1

版本
相關問題