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:
+2
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user