根据每当文档可以指定一组never_roles(https://github.com/javan/whenever#capistrano-roles)。现在我想在schedule.rb中定义一组cronjobs,并根据它们的角色划分它们,如下所示:
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?
非常感谢
答案 0 :(得分: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