File tree Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Original file line number Diff line number Diff line change 1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ #! /bin/bash
17+ # retry.sh: Executes a command with retries and exponential backoff.
18+ # Usage: ./retry.sh <command> [args...]
1619
17- set -euo pipefail
20+ set +o pipefail
1821
19- max_retries=${MAX_RETRIES:- 7 }
22+ max_retries=${MAX_RETRIES:- 3 }
2023backoff=${BACKOFF:- 1}
2124
2225retries=0
23- until (( retries == max_retries )) || " ${@ } " ; do
24- sleep " $(( (retries++ )* backoff )) "
26+ exit_status=0
27+
28+ while true ; do
29+ " ${@ } " 2>&1 | cat
30+
31+ exit_status=" ${PIPESTATUS[0]} "
32+
33+ if [ " $exit_status " -eq 0 ]; then
34+ exit 0
35+ fi
36+
37+ if (( retries == max_retries )) ; then
38+ echo " ❌ Command failed permanently with code $exit_status after $(( retries)) retries." >&2
39+ exit " $exit_status "
40+ fi
41+
42+ wait_time=$(( (retries++ ) * backoff ))
43+ echo " ⚠️ Command failed (exit code $exit_status ). Retrying in ${wait_time} seconds..." >&2
44+ sleep " ${wait_time} "
2545done
26- exit $?
You can’t perform that action at this time.
0 commit comments