我怎样才能缩短 capistrano 中的语句
How could I shorten the statement in capistrano
我必须在许多任务中放入 cd #{deploy_to}/current
和 raise_on_non_zero_exit: false
。闻起来很臭。
是否有任何内置函数可以让我缩短语句?
工头配置
namespace :foreman do
task :export do
on roles(:web) do |host|
execute %Q( cd #{deploy_to}/current && sudo foreman export upstart /etc/init -a #{ENV['APP_NAME']} -u #{ENV['DEPLOYER']} -l /var/#{ENV['APP_NAME']}/log )
end
end
task :start do
on roles(:web) do |host|
execute "cd #{deploy_to}/current && sudo start #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false
end
end
task :stop do
on roles(:web) do |host|
execute "cd #{deploy_to}/current && sudo stop #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false
end
end
end # foreman
您可以使用 capistranos 'within' 帮助程序稍微整理一下,以及将 raise 包装在您自己的帮助程序方法中吗?
within current_path do
execute_without_fail "..."
end
def execute_without_fail cmd
execute cmd, raise_on_non_zero_exit: false
end
我必须在许多任务中放入 cd #{deploy_to}/current
和 raise_on_non_zero_exit: false
。闻起来很臭。
是否有任何内置函数可以让我缩短语句?
工头配置
namespace :foreman do
task :export do
on roles(:web) do |host|
execute %Q( cd #{deploy_to}/current && sudo foreman export upstart /etc/init -a #{ENV['APP_NAME']} -u #{ENV['DEPLOYER']} -l /var/#{ENV['APP_NAME']}/log )
end
end
task :start do
on roles(:web) do |host|
execute "cd #{deploy_to}/current && sudo start #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false
end
end
task :stop do
on roles(:web) do |host|
execute "cd #{deploy_to}/current && sudo stop #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false
end
end
end # foreman
您可以使用 capistranos 'within' 帮助程序稍微整理一下,以及将 raise 包装在您自己的帮助程序方法中吗?
within current_path do
execute_without_fail "..."
end
def execute_without_fail cmd
execute cmd, raise_on_non_zero_exit: false
end