admin: add Total imported and Last sync columns to Garmin sync table
Matches the Strava sync table layout. Accumulates total_imported in garmin_sync.json state on each sync run; admin API exposes last_sync_at and total_imported from that file.
This commit is contained in:
@@ -174,6 +174,7 @@ def garmin_sync_iter(
|
||||
|
||||
# ── Persist sync state ─────────────────────────────────────────────────────
|
||||
state["last_sync_at"] = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
state["total_imported"] = state.get("total_imported", 0) + imported
|
||||
_save_sync_state(user_dir, state)
|
||||
|
||||
yield {
|
||||
|
||||
@@ -607,6 +607,17 @@ async def admin_garmin_sync_status(
|
||||
user_dir = cf.parent
|
||||
handle = user_dir.name
|
||||
|
||||
last_sync: str | None = None
|
||||
total_imported = 0
|
||||
sync_path = user_dir / "garmin_sync.json"
|
||||
if sync_path.exists():
|
||||
try:
|
||||
sc = json.loads(sync_path.read_text(encoding="utf-8"))
|
||||
last_sync = sc.get("last_sync_at")
|
||||
total_imported = sc.get("total_imported", 0)
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
|
||||
run_status: str | None = None
|
||||
run_imported = 0
|
||||
run_errors = 0
|
||||
@@ -626,6 +637,8 @@ async def admin_garmin_sync_status(
|
||||
|
||||
users.append({
|
||||
"handle": handle,
|
||||
"last_sync": last_sync,
|
||||
"total_imported": total_imported,
|
||||
"run_status": run_status,
|
||||
"run_imported": run_imported,
|
||||
"run_errors": run_errors,
|
||||
|
||||
Reference in New Issue
Block a user