Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/utils.sh')
-rw-r--r--scripts/utils.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/utils.sh b/scripts/utils.sh
index c71de666ac6..44bbabb4c99 100644
--- a/scripts/utils.sh
+++ b/scripts/utils.sh
@@ -10,6 +10,28 @@ function retry() {
return 0
fi
done
+
+ return 1
+}
+
+# Retry after 2s, 4s, 8s, 16s, 32, 64s, 128s
+function retry_exponential() {
+ if eval "$@"; then
+ return 0
+ fi
+
+ local sleep_time=0
+ # The last try will be after 2**7 = 128 seconds (2min8s)
+ for i in 1 2 3 4 5 6 7; do
+ sleep_time=$((2 ** i))
+
+ echo "Sleep for $sleep_time seconds..."
+ sleep $sleep_time
+ echo "[$(date '+%H:%M:%S')] Attempt #$i..."
+ if eval "$@"; then
+ return 0
+ fi
+ done
return 1
}