From ff17b881d8e8c5bc74297c1496b111540311b2b4 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Thu, 29 Oct 2026 11:45:54 -0700 Subject: [PATCH] discourse-release: wait and retry when the forum rate-limits Two releases published together (inbuxa-server's main and release/2026 on 2026-10-29) reached the forum 14 s apart; Discourse answered the second with 429 and the job failed. On 429 the script now waits the wait_seconds Discourse gives (15 s when it gives none, 60 s at most) and tries again, three times in all. A retry can't double-post: the external_id makes a repeat a 422, which is already treated as announced. --- discourse-release/announce.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/discourse-release/announce.sh b/discourse-release/announce.sh index fd46007..4ad8683 100755 --- a/discourse-release/announce.sh +++ b/discourse-release/announce.sh @@ -53,10 +53,19 @@ payload=$(jq -n --arg repo "$REPO" --argjson category "$category_id" --arg ext " ) }') -status=$(curl -sS -o /tmp/discourse-release.out -w '%{http_code}' -X POST "$FORUM/posts.json" \ - -H "Api-Key: $API_KEY" -H "Api-Username: release-bot" \ - -H "Content-Type: application/json" --data-binary "$payload") -body=$(cat /tmp/discourse-release.out) +# Two releases published together (a repo's main and its maintenance branch) +# hit the forum's rate limit: Discourse answers 429 with how long to wait. +# Wait that long (60 s at most) and try again, three times in all. +for attempt in 1 2 3; do + status=$(curl -sS -o /tmp/discourse-release.out -w '%{http_code}' -X POST "$FORUM/posts.json" \ + -H "Api-Key: $API_KEY" -H "Api-Username: release-bot" \ + -H "Content-Type: application/json" --data-binary "$payload") + body=$(cat /tmp/discourse-release.out) + [ "$status" = 429 ] && [ "$attempt" -lt 3 ] || break + delay=$(jq -r '(.extras.wait_seconds // 15) | if type == "number" then . else 15 end | if . > 60 then 60 else . end | ceil' <<<"$body" 2>/dev/null || echo 15) + echo "forum rate limit; trying again in $((delay + 1)) s" + sleep $((delay + 1)) +done case "$status" in 200) url="$FORUM/t/$(jq -r '.topic_slug' <<<"$body")/$(jq -r '.topic_id' <<<"$body")" -- 2.54.0