fix(retention): add retry on Gitea API errors
- Retry up to 3 times (2 retries) on non-200/non-404 responses - 10 second delay between retries - Fail-safe: keep report if all retries fail
This commit is contained in:
@@ -16,7 +16,7 @@ curl_with_host() {
|
||||
declare -A BRANCH_CACHE
|
||||
branch_exists() {
|
||||
local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}"
|
||||
local status
|
||||
local status attempt
|
||||
|
||||
[ -z "$GITEA_API_URL" ] && return 0
|
||||
[ -z "$GITEA_TOKEN" ] && return 0
|
||||
@@ -25,6 +25,8 @@ branch_exists() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Retry up to 2 times on API errors (hardcoded)
|
||||
for attempt in 1 2 3; do
|
||||
status=$(curl -sS -o /dev/null -w "%{http_code}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000")
|
||||
@@ -34,15 +36,21 @@ branch_exists() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# API error or branch not found - log warning and keep report (fail-safe)
|
||||
if [ "$status" != "404" ]; then
|
||||
echo " WARN: Gitea API error for ${owner}/${repo}/${branch} (status ${status}) - KEEPING report"
|
||||
BRANCH_CACHE[$key]=1 # cache as "exists" to avoid repeated errors
|
||||
return 0
|
||||
if [ "$status" = "404" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Actual 404 - branch truly doesn't exist
|
||||
return 1
|
||||
# API error - retry if not last attempt
|
||||
if [ "$attempt" -lt 3 ]; then
|
||||
sleep 10
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
# All retries failed - keep report (fail-safe)
|
||||
echo " WARN: Gitea API error for ${owner}/${repo}/${branch} (status ${status}) after 3 attempts - KEEPING report"
|
||||
BRANCH_CACHE[$key]=1
|
||||
return 0
|
||||
}
|
||||
|
||||
default_max_age=$(jq -r '.branches.default.maxAgeDays // 90' "$CONFIG")
|
||||
|
||||
Reference in New Issue
Block a user