@@ -161,7 +161,16 @@ def self.generate_strings_file_from_hash(translations:, output_path:)
161
161
# Typical examples include `{ status: 'current' }` or `{ status: 'review' }`.
162
162
# @param [String, IO] destination The path or `IO`-like instance, where to write the downloaded file on disk.
163
163
#
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
+ )
165
174
query_params = ( filters || { } ) . transform_keys { |k | "filters[#{ k } ]" } . merge ( format : 'strings' )
166
175
uri = URI . parse ( "#{ project_url . chomp ( '/' ) } /#{ locale } /default/export-translations/?#{ URI . encode_www_form ( query_params ) } " )
167
176
@@ -172,7 +181,27 @@ def self.download_glotpress_export_file(project_url:, locale:, filters:, destina
172
181
IO . copy_stream ( uri . open ( options ) , destination )
173
182
rescue StandardError => e
174
183
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
176
205
return nil
177
206
end
178
207
end
0 commit comments