models on tracker

This commit is contained in:
Dobromir Popov
2026-07-12 02:44:12 +03:00
parent 95d79a0a16
commit 9a1b15c020
7 changed files with 131 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ import random
import select
import socketserver
import sqlite3
import sys
import tarfile
import threading
import time
@@ -6738,19 +6739,32 @@ class TrackerServer:
delivered_all = False
return delivered_all
def _save_stats_once(self) -> None:
"""Persist each store independently so one DB failure cannot kill the loop."""
registry_log = getattr(self._contracts, "registry_log", None)
stores = (
("request stats", self._stats),
("route stats", self._route_stats),
("billing", self._billing),
("accounts", self._accounts),
("registry", registry_log),
)
for label, store in stores:
if store is None:
continue
try:
store.save_to_db()
except Exception as exc:
print(
f"[tracker] warn: {label} persistence failed: {exc}",
file=sys.stderr,
flush=True,
)
def _stats_loop(self) -> None:
"""Periodically save stats/billing to DB and push local slices to cluster peers."""
while not self._stats_stop.wait(_StatsCollector.SAVE_INTERVAL):
if self._stats is not None:
self._stats.save_to_db()
self._route_stats.save_to_db()
if self._billing is not None:
self._billing.save_to_db()
if self._accounts is not None:
self._accounts.save_to_db()
registry_log = getattr(self._contracts, "registry_log", None)
if registry_log is not None:
registry_log.save_to_db()
self._save_stats_once()
if self._cluster_peers and not self._hive_secret:
print(
"[tracker] WARNING: cluster peers configured without --hive-secret — "