From aab6c1c6fba95d8a09ef4658fe7f6b3f25912412 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 29 Apr 2024 09:49:03 +0700 Subject: [PATCH] fix(common): Retry curl downloads up to 5 times --- resources/build/build-download-resources.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/resources/build/build-download-resources.sh b/resources/build/build-download-resources.sh index 07cfbfc697e..fbaba819ef7 100755 --- a/resources/build/build-download-resources.sh +++ b/resources/build/build-download-resources.sh @@ -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 @@ -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 $?" } } @@ -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 $?" } }