Push last snapshot immediately to newly connected clients

The server keeps the most recent snapshot in memory (under the same
lock as the client list). When a client connects it receives that
snapshot right away, then continues to receive live updates on each
collection cycle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 19:57:36 +02:00
co-authored by Claude Sonnet 4.6
parent 53dcaf537e
commit 3ab7795248
2 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -95,7 +95,7 @@ def run(args: argparse.Namespace) -> None:
logs_dir.mkdir(exist_ok=True)
out = auto_out_path(logs_dir, vin)
push_clients, push_lock = network.start_push_server(args.host, args.port)
push_clients, push_lock, push_last = network.start_push_server(args.host, args.port)
current_day = datetime.now(timezone.utc).date()
store = load_store(out, vin, args.interval)
@@ -121,7 +121,7 @@ def run(args: argparse.Namespace) -> None:
snapshot = collect_snapshot(vehicle, domains)
store["records"].append(snapshot)
save_store(out, store, args.max_records)
network.broadcast(snapshot, push_clients, push_lock)
network.broadcast(snapshot, push_clients, push_lock, push_last)
log.info("Record #%d saved at %s", len(store["records"]), snapshot["ts"])
except KeyboardInterrupt:
raise