Skip to content

Commit

Permalink
fix: add max retry count
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Dec 8, 2024
1 parent e3fc82c commit 05409e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/service_scripts/build-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else
if [ ! -f "$FILE" ]; then
./scripts/build_scripts/build-all-in-flavor.sh "$FLAVOR" true
args=$(grep -v '^#' "$FLAVOR".env | grep -v '^$' | awk -F '=' '{print "--build-arg " $1 "=\"" $2 "\""}' ORS=' ')
./scripts/tool_scripts/exec-until-success.sh docker build --platform linux/amd64 "$args" -t "a-server:latest" .
./scripts/tool_scripts/exec-until-success.sh docker build . --platform linux/amd64 "$args" -t "a-server:latest"
else
echo "$FILE already exists. Skipping docker image build."
fi
Expand Down
21 changes: 16 additions & 5 deletions scripts/tool_scripts/exec-until-success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ fi
# 将所有的参数当做要执行的命令
COMMAND="$@"

# 无限循环执行命令直到成功
while true; do
#echo "Executing: $COMMAND"
# 设置最大重试次数
MAX_RETRIES=5
RETRY_COUNT=0

# 无限循环执行命令直到成功或达到最大重试次数
while true; do
# 执行命令
eval "$COMMAND"

Expand All @@ -21,7 +23,16 @@ while true; do
echo "Command succeeded."
break
else
echo "Command failed[$result]. Retrying..."
sleep 1 # 等待一秒再重试,避免过快的重试
# 增加重试次数
RETRY_COUNT=$((RETRY_COUNT + 1))

# 检查是否超过最大重试次数
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Command failed [$result]. Reached maximum retry limit ($MAX_RETRIES)."
exit 1
else
echo "Command failed [$result]. Retrying ($RETRY_COUNT/$MAX_RETRIES)..."
sleep 1 # 等待一秒再重试,避免过快的重试
fi
fi
done

0 comments on commit 05409e2

Please sign in to comment.