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
|
declare -A BRANCH_CACHE
|
||||||
branch_exists() {
|
branch_exists() {
|
||||||
local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}"
|
local owner="$1" repo="$2" branch="$3" key="${owner}/${repo}/${branch}"
|
||||||
local status
|
local status attempt
|
||||||
|
|
||||||
[ -z "$GITEA_API_URL" ] && return 0
|
[ -z "$GITEA_API_URL" ] && return 0
|
||||||
[ -z "$GITEA_TOKEN" ] && return 0
|
[ -z "$GITEA_TOKEN" ] && return 0
|
||||||
@@ -25,24 +25,32 @@ branch_exists() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
status=$(curl -sS -o /dev/null -w "%{http_code}" \
|
# Retry up to 2 times on API errors (hardcoded)
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
for attempt in 1 2 3; do
|
||||||
"${GITEA_API_URL}/api/v1/repos/${owner}/${repo}/branches/${branch}" 2>/dev/null || echo "000")
|
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")
|
||||||
|
|
||||||
if [ "$status" = "200" ]; then
|
if [ "$status" = "200" ]; then
|
||||||
BRANCH_CACHE[$key]=1
|
BRANCH_CACHE[$key]=1
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# API error or branch not found - log warning and keep report (fail-safe)
|
if [ "$status" = "404" ]; then
|
||||||
if [ "$status" != "404" ]; then
|
return 1
|
||||||
echo " WARN: Gitea API error for ${owner}/${repo}/${branch} (status ${status}) - KEEPING report"
|
fi
|
||||||
BRANCH_CACHE[$key]=1 # cache as "exists" to avoid repeated errors
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Actual 404 - branch truly doesn't exist
|
# API error - retry if not last attempt
|
||||||
return 1
|
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")
|
default_max_age=$(jq -r '.branches.default.maxAgeDays // 90' "$CONFIG")
|
||||||
|
|||||||
Reference in New Issue
Block a user