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