Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Add retry logic for downloading packages from pecl or via curl. Use e…
Browse files Browse the repository at this point in the history
…xponential backoff (#305)
  • Loading branch information
chingor13 authored Jun 5, 2017
1 parent 875e113 commit d42aab5
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions deb-package-builder/extensions/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

E_PARAM_ERR=250

with_retry()
{
# Execute command up to x times
# Usage:
# with_retry "pecl download apcu" 5
if [ -z "$2" ]; then
echo 'missing argument for retry. usage: with_retry <command> <max-attempts>'
exit $E_PARAM_ERR
fi

attempt=0
until [ $attempt -ge $2 ]
do
$1 && break
attempt=$[$attempt+1]
echo "command '$1' failed"
sleep $((2**$attempt))
done
}

download_from_pecl()
{
# Download the source code, rename, extract it for debian package
Expand All @@ -22,12 +42,12 @@ download_from_pecl()
PACKAGE_SHORT_NAME=$(basename ${PECL_PACKAGE_NAME} -beta)

if [ -z "$2" ]; then
pecl download "${PECL_PACKAGE_NAME}"
with_retry "pecl download ${PECL_PACKAGE_NAME}" 6
# determine the downloaded version
EXT_VERSION=$(ls ${PACKAGE_SHORT_NAME}-*.tgz | \
sed "s/${PACKAGE_SHORT_NAME}-\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\.tgz/\1/")
else
pecl download "${PECL_PACKAGE_NAME}-${2}"
with_retry "pecl download ${PECL_PACKAGE_NAME}-${2}" 6
EXT_VERSION="${2}"
fi

Expand Down Expand Up @@ -61,7 +81,7 @@ download_from_tarball()
PACKAGE_DIR=${PNAME}-${PACKAGE_VERSION}

# Download the file
curl -L $1 -o ${PNAME}-${PACKAGE_VERSION}.orig.tar.gz
with_retry "curl -L $1 -o ${PNAME}-${PACKAGE_VERSION}.orig.tar.gz" 6
mkdir -p ${PACKAGE_DIR}
tar zxf ${PNAME}-${PACKAGE_VERSION}.orig.tar.gz \
-C ${PACKAGE_DIR} --strip-components=1
Expand Down

0 comments on commit d42aab5

Please sign in to comment.