]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add ratelimit retry to discord changelog bot and continue publish changelog error...
authorMyra <vasilis@pikachu.systems>
Thu, 8 May 2025 16:30:50 +0000 (18:30 +0200)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 16:30:50 +0000 (18:30 +0200)
* Add ratelimit retry to discord changelog bot and continue publish changelog error.

oops we missed some changelogs cause of this... this should prevent anything funny

* Update actions_changelogs_since_last_run.py

.github/workflows/publish-testing.yml
.github/workflows/publish.yml
Tools/actions_changelogs_since_last_run.py

index aa3b35dea1747812872e8851aa1af11c368ee7d2..6dacef13244dbb027bb1c89730b2992bcc25fd07 100644 (file)
@@ -2,6 +2,7 @@
 
 concurrency:
   group: publish-testing
+  cancel-in-progress: true
 
 on:
   workflow_dispatch:
index 02fd9d404668f019846e4c922478b4e08f202e8c..029439563267b61fe01d30d7b1c29a2d583769aa 100644 (file)
@@ -2,6 +2,7 @@ name: Publish
 
 concurrency:
   group: publish
+  cancel-in-progress: true
 
 on:
   workflow_dispatch:
@@ -48,12 +49,14 @@ jobs:
         GITHUB_REPOSITORY: ${{ vars.GITHUB_REPOSITORY }}
 
     - name: Publish changelog (Discord)
+      continue-on-error: true
       run: Tools/actions_changelogs_since_last_run.py
       env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         DISCORD_WEBHOOK_URL: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}
 
     - name: Publish changelog (RSS)
+      continue-on-error: true
       run: Tools/actions_changelog_rss.py
       env:
         CHANGELOG_RSS_KEY: ${{ secrets.CHANGELOG_RSS_KEY }}
index 8261ad52391db1f4ea424fede4ae0ab777196c54..8df972d258f17ed8a9c8b2f15cc42462b51a7c2b 100755 (executable)
@@ -13,6 +13,7 @@ from typing import Any, Iterable
 
 import requests
 import yaml
+import time
 
 DEBUG = False
 DEBUG_CHANGELOG_FILE_OLD = Path("Resources/Changelog/Old.yml")
@@ -148,9 +149,23 @@ def get_discord_body(content: str):
 def send_discord_webhook(lines: list[str]):
     content = "".join(lines)
     body = get_discord_body(content)
-
-    response = requests.post(DISCORD_WEBHOOK_URL, json=body)
-    response.raise_for_status()
+    retry_attempt = 0
+
+    try:
+        response = requests.post(DISCORD_WEBHOOK_URL, json=body, timeout=10)
+        while response.status_code == 429:
+            retry_attempt += 1
+            if retry_attempt > 20:
+                print("Too many retries on a single request despite following retry_after header... giving up")
+                exit(1)
+            retry_after = response.json().get("retry_after", 5)
+            print(f"Rate limited, retrying after {retry_after} seconds")
+            time.sleep(retry_after)
+            response = requests.post(DISCORD_WEBHOOK_URL, json=body, timeout=10)
+        response.raise_for_status()
+    except requests.exceptions.RequestException as e:
+        print(f"Failed to send message: {e}")
+        exit(1)
 
 
 def changelog_entries_to_message_lines(entries: Iterable[ChangelogEntry]) -> list[str]: