From 96fdb4c8c54772fa6d5a4ed29cc6df8a2f65ee7b Mon Sep 17 00:00:00 2001 From: Edwin He Date: Wed, 28 Aug 2019 21:17:26 -0400 Subject: [PATCH] Batch rm -rf calls in deploy:cleanup. (#2027) --- CHANGELOG.md | 1 + features/deploy.feature | 6 ++++++ features/step_definitions/setup.rb | 10 ++++++---- lib/capistrano/tasks/deploy.rake | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e3110e..b614f41f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ gem "capistrano", github: "capistrano/capistrano", require: false [master]: https://github.com/capistrano/capistrano/compare/v3.11.0...HEAD * Your contribution here! +* [#2027](https://github.com/capistrano/capistrano/pull/2027): Batch rm -rf calls in deploy:cleanup. [@azin634](https://github.com/azin634) ## [`3.11.0`] (2018-06-02) diff --git a/features/deploy.feature b/features/deploy.feature index a8373ba4..4e97aa6a 100644 --- a/features/deploy.feature +++ b/features/deploy.feature @@ -70,6 +70,12 @@ Feature: Deploy Then 3 valid releases are kept And the current directory will be a symlink to the release + Scenario: Cleanup when there are more releases than arguments can handle + Given config stage file has line "set :keep_releases, 3" + And 5000 valid existing releases + When I run cap "deploy:cleanup" + Then 3 valid releases are kept + Scenario: Rolling Back Given I make 2 deployments When I run cap "deploy:rollback" diff --git a/features/step_definitions/setup.rb b/features/step_definitions/setup.rb index 6cd7a9ce..409796ec 100644 --- a/features/step_definitions/setup.rb +++ b/features/step_definitions/setup.rb @@ -80,10 +80,12 @@ end Given(/^(\d+) valid existing releases$/) do |num| a_day = 86_400 # in seconds - offset = -(a_day * num.to_i) - num.to_i.times do - run_vagrant_command("mkdir -p #{TestApp.release_path(TestApp.timestamp(offset))}") - offset += a_day + (1...num).each_slice(100) do |num_batch| + dirs = num_batch.map do |i| + offset = -(a_day * i) + TestApp.release_path(TestApp.timestamp(offset)) + end + run_vagrant_command("mkdir -p #{dirs.join(' ')}") end end diff --git a/lib/capistrano/tasks/deploy.rake b/lib/capistrano/tasks/deploy.rake index 617c7bca..28d5c5c8 100644 --- a/lib/capistrano/tasks/deploy.rake +++ b/lib/capistrano/tasks/deploy.rake @@ -168,7 +168,9 @@ namespace :deploy do debug t(:no_current_release, host: host.to_s) end if directories.any? - execute :rm, "-rf", *directories + directories.each_slice(100) do |directories_batch| + execute :rm, "-rf", *directories_batch + end else info t(:no_old_releases, host: host.to_s, keep_releases: fetch(:keep_releases)) end