Skip to content

Commit

Permalink
fix(common): Retry curl downloads up to 5 times
Browse files Browse the repository at this point in the history
  • Loading branch information
darcywong00 committed Apr 29, 2024
1 parent 5b1a4f0 commit aab6c1c
Showing 1 changed file with 11 additions and 6 deletions.
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`
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 $?"
}
}

0 comments on commit aab6c1c

Please sign in to comment.