From 13c650b8db63146b1bce1a4e3364cd6457908f2a Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 3 May 2021 10:11:26 -0700 Subject: [PATCH] RN: Retry `buck Fetch` in CircleCI Summary: Currently, various CircleCI jobs intermittently fail when trying to fetch dependencies via Maven. This adds a few retries before failing the CircleCI job to reduce noise from intermittent network fetch failures. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D28153008 fbshipit-source-id: ac944882ff0495f568973a709d6d61ef7b51b318 --- scripts/circleci/buck_fetch.sh | 46 ++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/scripts/circleci/buck_fetch.sh b/scripts/circleci/buck_fetch.sh index 5c4ca33a45b..d012c4ea057 100755 --- a/scripts/circleci/buck_fetch.sh +++ b/scripts/circleci/buck_fetch.sh @@ -6,8 +6,44 @@ set -ex -buck fetch ReactAndroid/src/test/java/com/facebook/react/modules -buck fetch ReactAndroid/src/main/java/com/facebook/react -buck fetch ReactAndroid/src/main/java/com/facebook/react/shell -buck fetch ReactAndroid/src/test/... -buck fetch ReactAndroid/src/androidTest/... +# Source: https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746 +# Modified to 1) address lint errors and 2) output to stderr. +# +# Retry a command up to a specific numer of times until it exits successfully, +# with exponential back off. +# +# $ retry 5 echo Hello +# Hello +# +# $ retry 5 false +# Retry 1/5 exited 1, retrying in 1 seconds... +# Retry 2/5 exited 1, retrying in 2 seconds... +# Retry 3/5 exited 1, retrying in 4 seconds... +# Retry 4/5 exited 1, retrying in 8 seconds... +# Retry 5/5 exited 1, no more retries left. +# +function retry { + local retries=$1 + shift + + local count=0 + until "$@"; do + exit=$? + wait=$((2 ** count)) + count=$((count + 1)) + if [ $count -lt "$retries" ]; then + echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." >&2 + sleep $wait + else + echo "Retry $count/$retries exited $exit, no more retries left." >&2 + return $exit + fi + done + return 0 +} + +retry 3 buck fetch ReactAndroid/src/test/java/com/facebook/react/modules +retry 3 buck fetch ReactAndroid/src/main/java/com/facebook/react +retry 3 buck fetch ReactAndroid/src/main/java/com/facebook/react/shell +retry 3 buck fetch ReactAndroid/src/test/... +retry 3 buck fetch ReactAndroid/src/androidTest/...