Skip to content
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

fix(common): Retry curl downloads up to 5 times #11314

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions resources/build/build-download-resources.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Download default keyboard and lexical model packages from downloads.keyman.com
# Retries up to 5 times

# Set sensible script defaults:
# set -e: Terminate script if a command returns an error
Expand Down Expand Up @@ -29,10 +30,12 @@ function downloadKeyboardPackage() {

local URL_DOWNLOAD=https://downloads.keyman.com
local URL_API_KEYBOARD_VERSION=${URL_DOWNLOAD}/api/keyboard/
local RETRY=5 # Curl retries this number of times before giving up
local RETRY_DELAY=5 # Make curl sleep this amount of time before each retry when a transfer has failed

echo "Downloading ${ID}.kmp from downloads.keyman.com"
local URL_DOWNLOAD_FILE=`curl -s "$URL_API_KEYBOARD_VERSION/${ID}" | "$JQ" -r .kmp`
curl -f -s "$URL_DOWNLOAD_FILE" -o "$KEYBOARDS_TARGET" || {
echo "Downloading ${ID}.kmp from downloads.keyman.com up to ${RETRY} attempts"
local URL_DOWNLOAD_FILE=`curl --silent "$URL_API_KEYBOARD_VERSION/${ID}" | "$JQ" -r .kmp`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't have a retry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, I can add it there too

curl --fail --retry "$RETRY" --retry-delay "$RETRY_DELAY" --silent "$URL_DOWNLOAD_FILE" --output "$KEYBOARDS_TARGET" || {
builder_die "Downloading $KEYBOARDS_TARGET failed with error $?"
}
}
Expand All @@ -48,10 +51,12 @@ function downloadModelPackage() {

local URL_DOWNLOAD=https://downloads.keyman.com
local URL_API_MODEL_VERSION=${URL_DOWNLOAD}/api/model/
local RETRY=5 # Curl retries this number of times before giving up
local RETRY_DELAY=5 # Make curl sleep this amount of time before each retry when a transfer has failed

echo "Downloading ${ID}.model.kmp from downloads.keyman.com"
local URL_DOWNLOAD_FILE=`curl -s "$URL_API_MODEL_VERSION/${ID}" | "$JQ" -r .kmp`
curl -f -s "$URL_DOWNLOAD_FILE" -o "$MODELS_TARGET" || {
echo "Downloading ${ID}.model.kmp from downloads.keyman.com up to ${RETRY} attempts"
local URL_DOWNLOAD_FILE=`curl --silent "$URL_API_MODEL_VERSION/${ID}" | "$JQ" -r .kmp`
curl --fail --retry "$RETRY" --retry-delay "$RETRY_DELAY" --silent "$URL_DOWNLOAD_FILE" --output "$MODELS_TARGET" || {
builder_die "Downloading $MODELS_TARGET failed with error $?"
}
}
Loading