Commit f9b871ce authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '10io-error-handling-in-container-expiration-policies-cleanup-service' into 'master'

Cleanup policies: put the unfinished cleanup state in case of an error

See merge request gitlab-org/gitlab!53853
parents d6748e44 759fe139
......@@ -15,9 +15,15 @@ module ContainerExpirationPolicies
repository.start_expiration_policy!
service_result = Projects::ContainerRepository::CleanupTagsService
.new(project, nil, policy_params.merge('container_expiration_policy' => true))
.execute(repository)
begin
service_result = Projects::ContainerRepository::CleanupTagsService
.new(project, nil, policy_params.merge('container_expiration_policy' => true))
.execute(repository)
rescue
repository.cleanup_unfinished!
raise
end
if service_result[:status] == :success
repository.update!(
......@@ -25,6 +31,7 @@ module ContainerExpirationPolicies
expiration_policy_started_at: nil,
expiration_policy_completed_at: Time.zone.now
)
success(:finished, service_result)
else
repository.cleanup_unfinished!
......
......@@ -97,5 +97,21 @@ RSpec.describe ContainerExpirationPolicies::CleanupService do
expect(response.success?).to eq(false)
end
end
context 'with a network error' do
before do
expect(Projects::ContainerRepository::CleanupTagsService)
.to receive(:new).and_raise(Faraday::TimeoutError)
end
it 'raises an error' do
expect { subject }.to raise_error(Faraday::TimeoutError)
expect(ContainerRepository.waiting_for_cleanup.count).to eq(1)
expect(repository.reload.cleanup_unfinished?).to be_truthy
expect(repository.expiration_policy_started_at).not_to eq(nil)
expect(repository.expiration_policy_completed_at).to eq(nil)
end
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