mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(ci): wait out the API rate limit in build validation (#2672)
* fix(ci): wait out the API rate limit in build validation * fix(ci): skip rate-limit sleep retries on status POSTs * fix(ci): detect status POSTs via --method without changing api() call signature
This commit is contained in:
1 parent
5fac78797f
commit
aba9811357
3 files changed
+61
-3
No files matched your search
@@ -2,13 +2,33 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from check_authorship import check_revision, event_violations
|
||||
|
||||
|
||||
def api(path, *args):
|
||||
return json.loads(subprocess.check_output(["gh", "api", path, *args], text=True))
|
||||
RATE_LIMIT_WAIT = 1800
|
||||
|
||||
|
||||
def rate_limit_wait():
|
||||
try:
|
||||
reset = json.loads(subprocess.check_output(["gh", "api", "rate_limit"], text=True))["resources"]["core"]["reset"]
|
||||
except (subprocess.CalledProcessError, KeyError, ValueError):
|
||||
return 60
|
||||
return max(5, min(RATE_LIMIT_WAIT, reset - time.time() + 5))
|
||||
|
||||
|
||||
def api(path, *args, attempts=3):
|
||||
for attempt in range(attempts):
|
||||
done = subprocess.run(["gh", "api", path, *args], text=True, capture_output=True)
|
||||
if done.returncode == 0:
|
||||
return json.loads(done.stdout)
|
||||
if "--method" in args or "rate limit" not in done.stderr.lower() or attempt == attempts - 1:
|
||||
sys.stderr.write(done.stderr)
|
||||
raise subprocess.CalledProcessError(done.returncode, done.args, done.stdout, done.stderr)
|
||||
time.sleep(rate_limit_wait())
|
||||
|
||||
|
||||
def compilation_state(run, jobs):
|
||||
|
||||
Reference in new issue
Block a user