feat: 添加重试逻辑以增强容器启动和微信通知的可靠性
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 39s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s

This commit is contained in:
2026-01-10 18:12:01 +08:00
parent f64e31b230
commit 9aeb9c825e

View File

@@ -53,7 +53,20 @@ jobs:
- name: Start containers - name: Start containers
run: | run: |
docker compose -p $COMPOSE_PROJECT_NAME down docker compose -p $COMPOSE_PROJECT_NAME down
docker compose -p $COMPOSE_PROJECT_NAME up -d --build
# 添加重试逻辑
RETRIES=3
DELAY=10
count=0
until docker compose -p $COMPOSE_PROJECT_NAME up -d --build; do
count=$((count+1))
if [ $count -ge $RETRIES ]; then
echo "Deployment failed after $RETRIES attempts"
exit 1
fi
echo "Deployment failed. Retrying in $DELAY seconds... ($count/$RETRIES)"
sleep $DELAY
done
cleanup: cleanup:
name: Cleanup Dangling Images name: Cleanup Dangling Images
@@ -97,6 +110,19 @@ jobs:
} }
EOF EOF
curl -s -X POST "$WEBHOOK_URL" \ # 添加重试逻辑
RETRIES=3
DELAY=5
count=0
# 使用 -f 让 curl 在 HTTP 错误时返回非零退出码
until curl -s -f -X POST "$WEBHOOK_URL" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d @wechat_payload.json -d @wechat_payload.json; do
count=$((count+1))
if [ $count -ge $RETRIES ]; then
echo "WeChat notification failed after $RETRIES attempts"
exit 1
fi
echo "Notification failed. Retrying in $DELAY seconds... ($count/$RETRIES)"
sleep $DELAY
done