Skip to content

Commit 010074e

Browse files
committed
Implement a prototype version of 429-auto-retry for iOS strings
1 parent 99a42e2 commit 010074e

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_helper.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ def self.generate_strings_file_from_hash(translations:, output_path:)
161161
# Typical examples include `{ status: 'current' }` or `{ status: 'review' }`.
162162
# @param [String, IO] destination The path or `IO`-like instance, where to write the downloaded file on disk.
163163
#
164-
def self.download_glotpress_export_file(project_url:, locale:, filters:, destination:)
164+
def self.download_glotpress_export_file(
165+
project_url:,
166+
locale:,
167+
filters:,
168+
destination:,
169+
autoretry: true,
170+
autoretry_count: 0,
171+
autoretry_max: Fastlane::Helper::MetadataDownloader::MAX_AUTO_RETRY_ATTEMPTS,
172+
autoretry_sleep: Fastlane::Helper::MetadataDownloader::AUTO_RETRY_SLEEP_TIME
173+
)
165174
query_params = (filters || {}).transform_keys { |k| "filters[#{k}]" }.merge(format: 'strings')
166175
uri = URI.parse("#{project_url.chomp('/')}/#{locale}/default/export-translations/?#{URI.encode_www_form(query_params)}")
167176

@@ -172,7 +181,27 @@ def self.download_glotpress_export_file(project_url:, locale:, filters:, destina
172181
IO.copy_stream(uri.open(options), destination)
173182
rescue StandardError => e
174183
UI.error "Error downloading locale `#{locale}` — #{e.message} (#{uri})"
175-
retry if e.is_a?(OpenURI::HTTPError) && UI.confirm("Retry downloading `#{locale}`?")
184+
if e.is_a?(OpenURI::HTTPError)
185+
if e.io.status[0] == '429' && autoretry
186+
if autoretry_count < autoretry_max
187+
UI.message("Received 429 for `#{locale}`. Auto retrying in #{autoretry_sleep} seconds...")
188+
sleep(autoretry_sleep)
189+
return download_glotpress_export_file(
190+
project_url: project_url,
191+
locale: locale,
192+
filters: filters,
193+
destination: destination,
194+
autoretry: autoretry,
195+
autoretry_count: autoretry_count + 1,
196+
autoretry_max: autoretry_max
197+
)
198+
else
199+
UI.user_error!("Abandoning `#{locale}` download after #{autoretry_max} attempts.")
200+
end
201+
elsif UI.confirm("Retry downloading `#{locale}`?")
202+
retry
203+
end
204+
end
176205
return nil
177206
end
178207
end

0 commit comments

Comments
 (0)