Gracefully handle the deletion of non-existing runners

This commit is contained in:
Sebastian Serth
2022-07-15 00:35:43 +02:00
parent 5707e4c914
commit 56eab88f88
2 changed files with 10 additions and 1 deletions

View File

@ -101,6 +101,8 @@ class Runner::Strategy::Poseidon < Runner::Strategy
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Destroying runner at #{runner_url}" } Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Destroying runner at #{runner_url}" }
response = self.class.http_connection.delete runner_url response = self.class.http_connection.delete runner_url
self.class.handle_error response unless response.status == 204 self.class.handle_error response unless response.status == 204
rescue Runner::Error::RunnerNotFound
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Runner not found, nothing to destroy" }
rescue Faraday::Error => e rescue Faraday::Error => e
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}") raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
ensure ensure

View File

@ -312,8 +312,15 @@ describe Runner::Strategy::Poseidon do
end end
end end
context 'when Poseidon returns NotFound (404)' do
let(:response_status) { 404 }
it 'raises an error' do
expect { action.call }.not_to raise_error(Runner::Error::RunnerNotFound)
end
end
include_examples 'Unauthorized (401) error handling' include_examples 'Unauthorized (401) error handling'
include_examples 'NotFound (404) error handling'
include_examples 'InternalServerError (500) error handling' include_examples 'InternalServerError (500) error handling'
include_examples 'unknown response status error handling' include_examples 'unknown response status error handling'
include_examples 'Faraday error handling' include_examples 'Faraday error handling'