|
4 | 4 | module Fastlane |
5 | 5 | module Helper |
6 | 6 | class MetadataDownloader |
| 7 | + AUTO_RETRY_SLEEP_TIME = 20 |
| 8 | + MAX_AUTO_RETRY_ATTEMPTS = 30 |
| 9 | + |
7 | 10 | attr_reader :target_folder, :target_files |
8 | 11 |
|
9 | | - def initialize(target_folder, target_files) |
| 12 | + def initialize(target_folder, target_files, auto_retry) |
10 | 13 | @target_folder = target_folder |
11 | 14 | @target_files = target_files |
| 15 | + @auto_retry = auto_retry |
12 | 16 | @alternates = {} |
| 17 | + @auto_retry_attempt_counter = 0 |
13 | 18 | end |
14 | 19 |
|
15 | 20 | # Downloads data from GlotPress, in JSON format |
@@ -112,8 +117,13 @@ def handle_glotpress_download(response:, locale:, is_source:) |
112 | 117 | UI.message("Received 301 for `#{locale}`. Following redirect...") |
113 | 118 | download(locale, response.header['location'], is_source) |
114 | 119 | when '429' |
115 | | - # We got rate-limited, offer to try again |
116 | | - if UI.confirm("Retry downloading `#{locale}` after receiving 429 from the API?") |
| 120 | + # We got rate-limited, auto_retry or offer to try again with a prompt |
| 121 | + if @auto_retry && @auto_retry_attempt_counter <= MAX_AUTO_RETRY_ATTEMPTS |
| 122 | + UI.message("Received 429 for `#{locale}`. Auto retrying in #{AUTO_RETRY_SLEEP_TIME} seconds...") |
| 123 | + sleep(AUTO_RETRY_SLEEP_TIME) |
| 124 | + @auto_retry_attempt_counter += 1 |
| 125 | + download(locale, response.uri, is_source) |
| 126 | + elsif UI.confirm("Retry downloading `#{locale}` after receiving 429 from the API?") |
117 | 127 | download(locale, response.uri, is_source) |
118 | 128 | else |
119 | 129 | UI.error("Abandoning `#{locale}` download as requested.") |
|
0 commit comments