Commit f8e3e133 authored by Kerri Miller's avatar Kerri Miller

Merge branch '357373-fix-destroying-a-destroyed-a-package-file' into 'master'

Packages cleanup artifact worker: avoid updating a deleted record

See merge request gitlab-org/gitlab!84700
parents 6db2ab05 6e29a3cb
......@@ -14,7 +14,9 @@ module Packages
artifact.destroy!
rescue StandardError
artifact&.update_column(:status, :error)
unless artifact&.destroyed?
artifact&.update_column(:status, :error)
end
end
after_destroy
......
......@@ -43,16 +43,36 @@ RSpec.describe Packages::CleanupPackageFileWorker do
end
end
context 'with an error during the destroy' do
context 'with a package file to destroy' do
let_it_be(:package_file) { create(:package_file, :pending_destruction) }
before do
expect(worker).to receive(:log_metadata).and_raise('Error!')
context 'with an error during the destroy' do
before do
expect(worker).to receive(:log_metadata).and_raise('Error!')
end
it 'handles the error' do
expect { subject }.to change { Packages::PackageFile.error.count }.from(0).to(1)
expect(package_file.reload).to be_error
end
end
it 'handles the error' do
expect { subject }.to change { Packages::PackageFile.error.count }.from(0).to(1)
expect(package_file.reload).to be_error
context 'when trying to destroy a destroyed record' do
before do
allow_next_found_instance_of(Packages::PackageFile) do |package_file|
destroy_method = package_file.method(:destroy!)
allow(package_file).to receive(:destroy!) do
destroy_method.call
raise 'Error!'
end
end
end
it 'handles the error' do
expect { subject }.to change { Packages::PackageFile.count }.by(-1)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment