mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user