summaryrefslogtreecommitdiff
path: root/tools/ci/scripts
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2023-09-10 12:21:56 +0200
committerFedja Beader <fedja@protonmail.ch>2023-09-10 12:21:56 +0200
commit1999cc4ec6a8d14730edb3c98dbf72011fce9ba6 (patch)
treedd19e82e95638394aecf4b06813b9fa016855f5e /tools/ci/scripts
parenta9c298915dc9984d99d75506c7a4dee55ec1fc99 (diff)
downloadmanaverse-1999cc4ec6a8d14730edb3c98dbf72011fce9ba6.tar.gz
manaverse-1999cc4ec6a8d14730edb3c98dbf72011fce9ba6.tar.bz2
manaverse-1999cc4ec6a8d14730edb3c98dbf72011fce9ba6.tar.xz
manaverse-1999cc4ec6a8d14730edb3c98dbf72011fce9ba6.zip
deduplicate repeating retries
Diffstat (limited to 'tools/ci/scripts')
-rwxr-xr-xtools/ci/scripts/init.sh97
1 files changed, 28 insertions, 69 deletions
diff --git a/tools/ci/scripts/init.sh b/tools/ci/scripts/init.sh
index f427be910..4b0764488 100755
--- a/tools/ci/scripts/init.sh
+++ b/tools/ci/scripts/init.sh
@@ -12,6 +12,29 @@ function do_init {
check_error $?
}
+retry_with_increasing_wait()
+{
+ local wait_time=1
+
+ while true; do
+ "$@"
+ local retval=$?
+
+ if [[ $retval -eq 0 || $wait_time -gt 16 ]]; then
+ break
+ fi
+
+ printf "command %s failed (exit code %d), waiting %d seconds until next try.\n"\
+ "$*" "$retval" "$wait_time"
+
+ sleep "$wait_time"
+ # 1, 2, 4, 8, 16...
+ (( wait_time = 2 * wait_time ))
+ done
+
+ return "$retval"
+}
+
function update_repos {
if [ "$RUNFROMSHELL" != "" ];
then
@@ -35,27 +58,8 @@ function aptget_update {
return
fi
echo "apt-get update"
- apt-get update
- if [ "$?" != 0 ]; then
- sleep 1s
- apt-get update
- if [ "$?" != 0 ]; then
- sleep 2s
- apt-get update
- if [ "$?" != 0 ]; then
- sleep 5s
- apt-get update
- if [ "$?" != 0 ]; then
- sleep 10s
- apt-get update
- if [ "$?" != 0 ]; then
- sleep 15s
- apt-get update
- fi
- fi
- fi
- fi
- fi
+
+ retry_with_increasing_wait apt-get update
}
function aptget_install {
@@ -66,31 +70,10 @@ function aptget_install {
fi
update_repos
- aptget_update
+ retry_with_increasing_wait aptget_update
echo "apt-get -y -qq install $*"
- apt-get -y -qq install $*
- if [ "$?" != 0 ]; then
- sleep 1s
- apt-get -y -qq install $*
- if [ "$?" != 0 ]; then
- sleep 2s
- apt-get -y -qq install $*
- if [ "$?" != 0 ]; then
- sleep 5s
- apt-get -y -qq install $*
- if [ "$?" != 0 ]; then
- sleep 10s
- aptget_update
- apt-get -y -qq install $*
- if [ "$?" != 0 ]; then
- sleep 15s
- apt-get -y -qq install $*
- fi
- fi
- fi
- fi
- fi
+ retry_with_increasing_wait apt-get -y -qq install "$@"
}
function gitclone1 {
@@ -109,31 +92,7 @@ function gitclone {
export name2=${CI_BUILD_REPO##*@}
export name2=https://${name2%/*}/$2
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 1s
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 3s
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 5s
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 10s
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 15s
- gitclone1 "$name1" "$name2"
- if [ "$?" != 0 ]; then
- sleep 20s
- gitclone1 "$name1" "$name2"
- fi
- fi
- fi
- fi
- fi
- fi
+ retry_with_increasing_wait gitclone1 "$name1" "$name2"
check_error $?
}