Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

More resilient schema lookup #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/iglu-client/registries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ def initialize(config, uri)
@uri = uri
end

def lookup_schema(schema_key)
def lookup_schema(schema_key, max_retries = 3)
schema_uri = "#{@uri}/schemas/#{schema_key.as_path}"
times_retried = 0

begin
response = HTTParty.get(schema_uri)
response = HTTParty.get(schema_uri, timeout: 3)
rescue SocketError => _
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just thinking that we might also want to retry on the SocketError 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on that. But leaning towards not retrying on the SocketError as this is rarely something that can be fixed by bigger delay.

raise IgluError.new "Iglu registry #{config.name} is not available"
rescue Net::ReadTimeout => e
if times_retried < max_retries
times_retried += 1
retry
else
raise e
end
end

if response.code == 200
JSON::parse(response.body)
else
Expand Down