fix: handle MaxMind 429 and backoff
This commit is contained in:
@@ -15,3 +15,6 @@ PDB_INFO_TYPE=Educational/Research
|
|||||||
|
|
||||||
# minimum ASN entries for healthy /healthz
|
# minimum ASN entries for healthy /healthz
|
||||||
MIN_ASN_COUNT=10
|
MIN_ASN_COUNT=10
|
||||||
|
|
||||||
|
# retry interval after a failed update (e.g., MaxMind 429)
|
||||||
|
RETRY_SECONDS=3600
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
INTERVAL_SECONDS="${INTERVAL_SECONDS:-2592000}"
|
INTERVAL_SECONDS="${INTERVAL_SECONDS:-2592000}"
|
||||||
|
RETRY_SECONDS="${RETRY_SECONDS:-3600}"
|
||||||
echo "[start] updater interval=${INTERVAL_SECONDS}s out_dir=${OUT_DIR:-/data}"
|
echo "[start] updater interval=${INTERVAL_SECONDS}s out_dir=${OUT_DIR:-/data}"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo "[run] update now"
|
echo "[run] update now"
|
||||||
python /app/update.py
|
if python /app/update.py; then
|
||||||
echo "[sleep] ${INTERVAL_SECONDS}s"
|
echo "[sleep] ${INTERVAL_SECONDS}s"
|
||||||
sleep "${INTERVAL_SECONDS}"
|
sleep "${INTERVAL_SECONDS}"
|
||||||
|
else
|
||||||
|
echo "[warn] update failed; retry in ${RETRY_SECONDS}s"
|
||||||
|
sleep "${RETRY_SECONDS}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ def download_maxmind_mmdb() -> None:
|
|||||||
with tempfile.TemporaryDirectory() as td:
|
with tempfile.TemporaryDirectory() as td:
|
||||||
tgz = os.path.join(td, "GeoLite2-ASN.tar.gz")
|
tgz = os.path.join(td, "GeoLite2-ASN.tar.gz")
|
||||||
r = requests.get(url, timeout=TIMEOUT)
|
r = requests.get(url, timeout=TIMEOUT)
|
||||||
|
if r.status_code == 429:
|
||||||
|
existing = os.path.join(OUT_DIR, "GeoLite2-ASN.mmdb")
|
||||||
|
if os.path.exists(existing):
|
||||||
|
print("[warn] MaxMind rate limited (429); keeping existing mmdb")
|
||||||
|
return
|
||||||
|
raise RuntimeError("MaxMind rate limited (429) and no existing mmdb")
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
with open(tgz, "wb") as f:
|
with open(tgz, "wb") as f:
|
||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user