- searcher: file-based instance list (mtime-reloaded, hand-editable), failover across instances, URL normalization + dedup, Redis search cache (300s TTL) - searxng: pinned settings.yml with JSON format enabled and limiter disabled, secret from SEARXNG_SECRET env; wired into compose with config volume - orchestrator: /search proxying the searcher with per-stage trace; searcher included in aggregated /health Verified against a mock SearXNG: failover past a dead instance, dedup of trailing-slash duplicates, non-http URL filtering, cache miss/hit flags. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
30 lines
883 B
Python
30 lines
883 B
Python
"""File-based SearXNG instance list.
|
|
|
|
Re-read (mtime-checked) on every access so hand edits apply without restart.
|
|
MVP runs failover over this list; fan-out/rotation reuse the same source later.
|
|
"""
|
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
INSTANCES_FILE = os.environ.get("INSTANCES_FILE", "/config/instances.yml")
|
|
|
|
_cache: dict = {"mtime": None, "instances": []}
|
|
|
|
|
|
def load_instances() -> list[dict]:
|
|
try:
|
|
mtime = os.path.getmtime(INSTANCES_FILE)
|
|
except OSError:
|
|
return []
|
|
if _cache["mtime"] != mtime:
|
|
with open(INSTANCES_FILE) as f:
|
|
data = yaml.safe_load(f) or {}
|
|
_cache["instances"] = [
|
|
{"name": i.get("name", i["url"]), "url": i["url"].rstrip("/"), "weight": i.get("weight", 1)}
|
|
for i in data.get("instances", [])
|
|
if i.get("url")
|
|
]
|
|
_cache["mtime"] = mtime
|
|
return _cache["instances"]
|