fix(launch): back off build retries on GitHub limits, dedupe fetcher misses, no ad hoc render before first build

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shay
2026-11-30 09:11:03 -08:00
co-authored by Claude Opus 5.5
parent d907815f19
commit d4b4a8bc52
8 changed files with 147 additions and 4 deletions
+16
View File
@@ -1,10 +1,13 @@
"""Flask app for the fetcher service. All endpoints require X-Internal-Token."""
import fcntl
import hmac
import logging
import os
import re
import threading
import time
import requests
import tempfile
from concurrent.futures import ThreadPoolExecutor
from flask import Flask, jsonify, request, Response
from functools import wraps
@@ -31,6 +34,10 @@ _BG_POOL = ThreadPoolExecutor(
# fetcher container; a multi-replica deploy would need a distributed lock.
_INFLIGHT: set[str] = set()
_INFLIGHT_LOCK = threading.Lock()
# /data misses for the same user (worker build, ad hoc renders, cron) used to
# each run a full GitHub fetch. gunicorn runs sync worker processes, so the
# lock is a per-username file lock that all workers in the container share.
_MISS_LOCK_DIR = tempfile.gettempdir()
# Must stay in sync with github.py's _USERNAME_RE. Trust boundary: the
# fetcher is called only by the generator over the internal network, but
@@ -81,6 +88,15 @@ def metrics():
def get_data(username: str):
if not _valid_username(username):
return jsonify({"error": "invalid_username"}), 400
if db.get_user(username) is None:
path = os.path.join(_MISS_LOCK_DIR, f"ghstats-miss-{username.lower()}.lock")
with open(path, "w") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
return _get_data(username)
return _get_data(username)
def _get_data(username: str):
row = db.get_user(username)
if row is None:
# Auto-fetch path