server: remove diff switch, always send diffs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+2
-5
@@ -6,9 +6,10 @@ from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from . import log_config, network, we_connect
|
||||
from jaydiff.diff import diff_full as jay_diff_full
|
||||
|
||||
from .data_model import ALL_DOMAINS, apply_procedural, extract_all
|
||||
from .storage_helpers import auto_out_path, load_last_24h_records, load_store, save_store
|
||||
from jaydiff.diff import diff_full as jay_diff_full
|
||||
|
||||
from volkswagencarnet.vw_exceptions import AuthenticationError
|
||||
|
||||
@@ -46,7 +47,6 @@ def run(args: argparse.Namespace) -> None:
|
||||
out = auto_out_path(logs_dir, vin)
|
||||
|
||||
push_clients, push_lock, push_store_ref = network.start_push_server(args.host, args.port)
|
||||
push_store_ref["diff_mode"] = args.diff
|
||||
push_store_ref["preloaded"] = load_last_24h_records(logs_dir, vin)
|
||||
for _r in push_store_ref["preloaded"]:
|
||||
if "procedural" not in _r:
|
||||
@@ -89,10 +89,7 @@ def run(args: argparse.Namespace) -> None:
|
||||
snapshot = apply_procedural(snapshot)
|
||||
store["records"].append(snapshot)
|
||||
save_store(out, store, args.max_records)
|
||||
if args.diff:
|
||||
payload = jay_diff_full(last_broadcast, snapshot, combine_upd_add=True)
|
||||
else:
|
||||
payload = snapshot
|
||||
last_broadcast = snapshot
|
||||
network.broadcast(payload, push_clients, push_lock)
|
||||
log.info("Record #%d saved at %s", len(store["records"]), snapshot["ts"])
|
||||
|
||||
@@ -120,12 +120,6 @@ def main() -> None:
|
||||
help="Directory for rotating log files (overrides credentials file, default: ./logs)",
|
||||
)
|
||||
p.add_argument("-v", "--verbose", action="store_true", help="Enable debug logging")
|
||||
p.add_argument(
|
||||
"--diff",
|
||||
action="store_true",
|
||||
default=None,
|
||||
help="Send diffs instead of full snapshots over the push server (overrides credentials file, default: off)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--dry",
|
||||
action="store_true",
|
||||
@@ -176,9 +170,6 @@ def main() -> None:
|
||||
args.port = int(creds_data.get("port", 9999))
|
||||
if args.log_dir is None:
|
||||
args.log_dir = creds_data.get("log_dir", "./logs")
|
||||
if args.diff is None:
|
||||
args.diff = bool(creds_data.get("diff", False))
|
||||
|
||||
if not args.dry and (not args.username or not args.password):
|
||||
p.error(
|
||||
"Username and password are required. "
|
||||
|
||||
+1
-5
@@ -31,15 +31,11 @@ def _accept_loop(
|
||||
records = in_mem
|
||||
|
||||
try:
|
||||
if store_ref.get("diff_mode"):
|
||||
prev: dict = {}
|
||||
for record in records:
|
||||
diff = jay_diff_full(prev, record, combine_upd_add=True)
|
||||
prev = record
|
||||
conn.sendall((json.dumps(diff, default=str) + "\n").encode())
|
||||
else:
|
||||
for record in records:
|
||||
conn.sendall((json.dumps(record, default=str) + "\n").encode())
|
||||
if records:
|
||||
log.info("Sent %d record(s) to %s", len(records), addr)
|
||||
except OSError:
|
||||
@@ -73,7 +69,7 @@ def start_push_server(host: str, port: int) -> tuple:
|
||||
server_sock.listen()
|
||||
clients: list = []
|
||||
lock = threading.Lock()
|
||||
store_ref: dict = {"current": None, "preloaded": [], "diff_mode": False}
|
||||
store_ref: dict = {"current": None, "preloaded": []}
|
||||
t = threading.Thread(
|
||||
target=_accept_loop,
|
||||
args=(server_sock, clients, lock, store_ref),
|
||||
|
||||
Reference in New Issue
Block a user