From cc886f4cdc4bed1fb7b1e454526cbe62ceb50575 Mon Sep 17 00:00:00 2001 From: Darren Worrall Date: Wed, 13 Nov 2024 16:01:55 +0000 Subject: [PATCH] Fix stack deletion take two --- app/jobs/shipit/destroy_stack_job.rb | 11 +++++++++-- test/jobs/destroy_stack_job_test.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/jobs/shipit/destroy_stack_job.rb b/app/jobs/shipit/destroy_stack_job.rb index 585b226a0..6d26fa7d2 100644 --- a/app/jobs/shipit/destroy_stack_job.rb +++ b/app/jobs/shipit/destroy_stack_job.rb @@ -22,8 +22,15 @@ def perform(stack) commit_deployments_ids = Shipit::CommitDeployment.where(task_id: tasks_ids).pluck(:id) Shipit::CommitDeploymentStatus.where(commit_deployment_id: commit_deployments_ids).in_batches(&:delete_all) Shipit::CommitDeployment.where(id: commit_deployments_ids).in_batches(&:delete_all) - Shipit::Status.where(commit_id: commits_ids).in_batches(&:delete_all) - Shipit::Commit.where(id: commits_ids).in_batches(&:delete_all) + + Shipit::Status.where(commit_id: commits_ids).find_in_batches do |batch| + Shipit::Status.where(id: batch.map(&:id)).delete_all + end + + Shipit::Commit.where(id: commits_ids).find_in_batches do |batch| + Shipit::Commit.where(id: batch.map(&:id)).delete_all + end + Shipit::GithubHook.where(stack_id: stack.id).destroy_all Shipit::Hook.where(stack_id: stack.id).in_batches(&:delete_all) Shipit::MergeRequest.where(stack_id: stack.id).in_batches(&:delete_all) diff --git a/test/jobs/destroy_stack_job_test.rb b/test/jobs/destroy_stack_job_test.rb index 48e817f75..8262d9100 100644 --- a/test/jobs/destroy_stack_job_test.rb +++ b/test/jobs/destroy_stack_job_test.rb @@ -24,5 +24,16 @@ class DestroyStackJobTest < ActiveSupport::TestCase @job.perform(stack) end end + + test "perform destroys the all Status of related commits" do + stack = shipit_stacks(:shipit) + Shipit.legacy_github_api.stubs(:remove_hook) + + assert_changes -> { Status.count }, 'Statuses are not deleted' do + @job.perform(stack) + end + + refute_predicate Status.count, :zero? + end end end