Skip to content

Commit

Permalink
Redo retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
axsuul committed Nov 12, 2023
1 parent f24038c commit 832c12b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/middleware/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,10 @@ def fetch_media_section_count(key:, params: {}, **options)
end

def send_plex_api_request(method:, endpoint:, **options)
count = 0
retries_count = 0

# Keep trying request if it fails until number of retries have been exhausted
loop do
count += 1
response = HTTP
.timeout(@plex_timeout)
.headers(
Expand All @@ -219,9 +218,10 @@ def send_plex_api_request(method:, endpoint:, **options)
.public_send(method, "#{@plex_addr}#{endpoint}", **options)

return JSON.parse(response)

rescue HTTP::Error => e
raise(e) unless @plex_retries_count <= count
raise(e) if retries_count >= @plex_retries_count

retries_count += 1
end
end

Expand Down

0 comments on commit 832c12b

Please sign in to comment.