discourse-release: wait and retry when the forum rate-limits #10
@@ -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")"
|
||||
|
||||
Reference in new issue
Block a user