Commit 759fe139 authored by David Fernandez's avatar David Fernandez

Properly handle error conditions

If an error occurs with the cleanup tags service, put the
container repository back to unfinished.
parent 91dc753a
......@@ -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