This commit is contained in:
1 parent
2dbe457836
commit
d860157540
10 files changed
+91
-11
No files matched your search
@@ -51,6 +51,17 @@ LIB_CACHE = os.path.join(STEAM_ROOT, "appcache", "librarycache") if STEAM_ROOT e
|
||||
CACHE_DIR = os.path.join(BASE, "cache", "covers")
|
||||
IMAGE_LOCK = threading.Lock()
|
||||
COVER_MISSING_TTL = 7 * 24 * 60 * 60
|
||||
|
||||
|
||||
def _env_float(name, default):
|
||||
try:
|
||||
return float(os.environ.get(name, default))
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
COVER_MAINTENANCE_HOURS = _env_float("STEAMBASE_COVER_MAINTENANCE_HOURS", 24)
|
||||
COVER_MAX_MB = _env_float("STEAMBASE_COVER_MAX_MB", 500)
|
||||
CACHE_COVER_NAMES = steam_source.COVER_ORDER
|
||||
PROGRESS_RE = re.compile(r"^\s*(\d+)/(\d+)\b")
|
||||
|
||||
@@ -78,6 +89,27 @@ def log_event(event, **fields):
|
||||
record = {"ts": datetime.now(timezone.utc).isoformat(timespec="seconds"), "event": event}
|
||||
record.update(fields)
|
||||
LOG.info(json.dumps(record, ensure_ascii=False))
|
||||
|
||||
|
||||
def cover_maintenance():
|
||||
markers = covers.cleanup_negative_markers(CACHE_DIR, COVER_MISSING_TTL)
|
||||
pruned = 0
|
||||
left = None
|
||||
if COVER_MAX_MB > 0:
|
||||
result = covers.prune_cache(CACHE_DIR, int(COVER_MAX_MB * 1024 * 1024))
|
||||
pruned = result["removed"]
|
||||
left = result["bytes"]
|
||||
log_event("cover_maintenance", markers_removed=markers, pruned=pruned)
|
||||
return {"markers_removed": markers, "pruned": pruned, "bytes": left}
|
||||
|
||||
|
||||
def cover_maintenance_loop():
|
||||
while True:
|
||||
try:
|
||||
cover_maintenance()
|
||||
except Exception as exc:
|
||||
log_event("cover_maintenance_error", error=str(exc))
|
||||
time.sleep(max(1.0, COVER_MAINTENANCE_HOURS) * 3600)
|
||||
CDN_COVER_NAMES = (
|
||||
"library_600x900.jpg",
|
||||
"library_capsule.jpg",
|
||||
@@ -1402,6 +1434,8 @@ def main():
|
||||
db.seed_moods(con)
|
||||
con.close()
|
||||
DETAILS = DetailsService(db.DEFAULT_DB, delay=1.4)
|
||||
if COVER_MAINTENANCE_HOURS > 0:
|
||||
threading.Thread(target=cover_maintenance_loop, daemon=True).start()
|
||||
|
||||
url = f"http://{args.host}:{args.port}/"
|
||||
log_event("server_start", host=args.host, port=args.port)
|
||||
|
||||
Reference in new issue
Block a user