From a8f333783683172eb28035224f702212fee2f3d0 Mon Sep 17 00:00:00 2001 From: Gabor Pongracz Date: Mon, 15 Jan 2024 14:42:46 +0100 Subject: [PATCH] Add faraday retry --- .gitignore | 2 +- app_store_connect_api.gemspec | 1 + lib/app_store_connect_api.rb | 1 + lib/app_store_connect_api/client.rb | 7 ++++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cacbb7b..0c50365 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ /pkg/ /spec/reports/ /tmp/ - +/.idea # rspec failure tracking .rspec_status .ruby-version diff --git a/app_store_connect_api.gemspec b/app_store_connect_api.gemspec index a61fffc..8c24643 100644 --- a/app_store_connect_api.gemspec +++ b/app_store_connect_api.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "faraday" + spec.add_dependency "faraday-retry" spec.add_dependency "jwt" spec.add_development_dependency "rake" diff --git a/lib/app_store_connect_api.rb b/lib/app_store_connect_api.rb index 260789d..57a8a9b 100644 --- a/lib/app_store_connect_api.rb +++ b/lib/app_store_connect_api.rb @@ -3,6 +3,7 @@ require 'openssl' require 'jwt' require 'faraday' +require 'faraday/retry' require_relative "app_store_connect_api/client" require_relative "app_store_connect_api/version" diff --git a/lib/app_store_connect_api/client.rb b/lib/app_store_connect_api/client.rb index cef1d64..31d2981 100644 --- a/lib/app_store_connect_api/client.rb +++ b/lib/app_store_connect_api/client.rb @@ -67,9 +67,14 @@ def connection @connection ||= Faraday.new(url: APP_STORE_CONNECT_API_ROOT_URL, request: { timeout: @request_timeout }, headers: { 'Authorization' => "Bearer #{@authorization.token}" }) do |f| + + f.request :retry, + max: 3, + interval: 1, + interval_randomness: 0.2, + backoff_factor: 1.5 f.request :json f.response :json, content_type: /\bjson$/ - f.adapter :net_http end end end