Skip to content

Commit 8fa9163

Browse files
committed
Adds the option to auto-retry for downloading metadata from GlotPress
1 parent 4df4c38 commit 8fa9163

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ def self.run(params)
1010
UI.message "Locales: #{params[:locales].inspect}"
1111
UI.message "Source locale: #{params[:source_locale].nil? ? '-' : params[:source_locale]}"
1212
UI.message "Path: #{params[:download_path]}"
13+
UI.message "Auto-retry: #{params[:auto_retry]}"
1314

1415
# Check download path
1516
FileUtils.mkdir_p(params[:download_path])
1617

1718
# Download
18-
downloader = Fastlane::Helper::MetadataDownloader.new(params[:download_path], params[:target_files])
19+
downloader = Fastlane::Helper::MetadataDownloader.new(params[:download_path], params[:target_files], params[:auto_retry])
1920

2021
params[:locales].each do |loc|
2122
if loc.is_a?(Array)
@@ -68,6 +69,12 @@ def self.available_options
6869
env_name: 'FL_DOWNLOAD_METADATA_DOWNLOAD_PATH',
6970
description: 'The path of the target files',
7071
type: String),
72+
FastlaneCore::ConfigItem.new(key: :auto_retry,
73+
env_name: 'FL_DOWNLOAD_METADATA_AUTO_RETRY',
74+
description: 'Whether to auto retry downloads after Too Many Requests error',
75+
type: FastlaneCore::Boolean,
76+
optional: true,
77+
default_value: false),
7178
]
7279
end
7380

lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
module Fastlane
55
module Helper
66
class MetadataDownloader
7+
AUTO_RETRY_SLEEP_TIME = 20
8+
79
attr_reader :target_folder, :target_files
810

9-
def initialize(target_folder, target_files)
11+
def initialize(target_folder, target_files, auto_retry)
1012
@target_folder = target_folder
1113
@target_files = target_files
14+
@auto_retry = auto_retry
1215
@alternates = {}
1316
end
1417

@@ -112,8 +115,12 @@ def handle_glotpress_download(response:, locale:, is_source:)
112115
UI.message("Received 301 for `#{locale}`. Following redirect...")
113116
download(locale, response.header['location'], is_source)
114117
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?")
117124
download(locale, response.uri, is_source)
118125
else
119126
UI.error("Abandoning `#{locale}` download as requested.")

0 commit comments

Comments
 (0)