-
Notifications
You must be signed in to change notification settings - Fork 9
Adds the option to auto-retry for downloading metadata from GlotPress #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8fa9163
17ca0b7
5c19fca
dc56ef0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,17 @@ | |
| module Fastlane | ||
| module Helper | ||
| class MetadataDownloader | ||
| AUTO_RETRY_SLEEP_TIME = 20 | ||
| MAX_AUTO_RETRY_ATTEMPTS = 30 | ||
|
|
||
| attr_reader :target_folder, :target_files | ||
|
|
||
| def initialize(target_folder, target_files) | ||
| def initialize(target_folder, target_files, auto_retry) | ||
| @target_folder = target_folder | ||
| @target_files = target_files | ||
| @auto_retry = auto_retry | ||
| @alternates = {} | ||
| @auto_retry_attempt_counter = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just happened to me that the This means that if you only set the Was this intentional to consider that For example, maybe you could move the current 3 LoC implementation of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was intentional. The only goal I had with this attempt counter is so that we wouldn't get into an infinite loop. I don't think we'll ever hit this limit unless there is an issue with the server or CI in which case, I thought it'd be best to stop and let the release manager handle it either manually or by retrying once the issue is resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM 👍 |
||
| end | ||
|
|
||
| # Downloads data from GlotPress, in JSON format | ||
|
|
@@ -112,8 +117,13 @@ def handle_glotpress_download(response:, locale:, is_source:) | |
| UI.message("Received 301 for `#{locale}`. Following redirect...") | ||
| download(locale, response.header['location'], is_source) | ||
| when '429' | ||
| # We got rate-limited, offer to try again | ||
| if UI.confirm("Retry downloading `#{locale}` after receiving 429 from the API?") | ||
| # We got rate-limited, auto_retry or offer to try again with a prompt | ||
| if @auto_retry && @auto_retry_attempt_counter <= MAX_AUTO_RETRY_ATTEMPTS | ||
| UI.message("Received 429 for `#{locale}`. Auto retrying in #{AUTO_RETRY_SLEEP_TIME} seconds...") | ||
| sleep(AUTO_RETRY_SLEEP_TIME) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we wouldn't benefit from a linear or exponential wait time between attempts instead of a fixed time? e.g.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've considered this one, but in my experience, it's really not necessary. I think the server just checks the number of requests in a certain amount of time, but I could be wrong. For what it's worth, I actually wanted to go with something shorter, but since it's in CI, it doesn't really matter if it takes 1 or 2 minutes longer. Funnily enough, I tried to create the Happy to apply the suggestion if you feel there is enough benefit. |
||
| @auto_retry_attempt_counter += 1 | ||
| download(locale, response.uri, is_source) | ||
| elsif UI.confirm("Retry downloading `#{locale}` after receiving 429 from the API?") | ||
| download(locale, response.uri, is_source) | ||
| else | ||
| UI.error("Abandoning `#{locale}` download as requested.") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it wouldn't make more sense to have the
auto_retryConfigItem be anIntegerthat would allow to set that max-retry-attempts value?That way we could use a value like 30 (!) for CI because we really need to be sure to end up in success, while we could use a value like 3 for repos still doing manual release, because it'd be nice not to have to
UI.confirmthe retry manually every time this happens just on the first or second try, but if it fails consistently more than 3 times we might want to wait longer when confirming manually.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a cool idea. I could make that change if there is practical use for it for others or if you feel strongly that it is a better approach.
My understanding is that, this issue is mostly specific to WPAndroid & WPiOS and as you mentioned it's a temporary one. That's why I did this in the most straightforward way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I don't feel strongly about it.