v / .github / workflows / retry.sh
22 lines · 18 sloc · 433 bytes · 2a651396cfd423c1f83c0ef0e9640467b3744ac1
Raw
1#!/usr/bin/env bash
2
3cmd=$@
4
5function elog() {
6 message=$1
7 printf "%(%Y/%m/%d %H:%M:%S)T | retry.sh $1\n"
8}
9
10declare -i iteration=0
11declare -i max_iterations=9
12for((iteration=1;iteration<=max_iterations;iteration++)); do
13 elog "iteration: $iteration/$max_iterations, cmd: $cmd"
14 if $cmd; then
15 exit 0
16 fi
17 elog "command failed, retrying ...";
18 sleep 1;
19done;
20
21elog "failed doing $max_iterations iterations of command: $cmd"
22exit 1
23