Flag LiveTrack sessions whose map Garmin no longer serves
CI / check (push) Successful in 42s
CI / deploy (push) Successful in 20s

Ended sessions past the ~24h Garmin appears to keep a live-track page
around for get verified once at app startup and, once confirmed dead,
flagged so the panel greys them out instead of only failing after a
click. Already-flagged sessions are skipped on later startups so this
doesn't keep re-hitting Garmin for the same dead session.
This commit is contained in:
randy committed 2026-09-08 14:19:15 +02:00
1 parent 141b7a08ce
commit 0c4ee97368
5 files changed
+98 -3

No files matched your search

+39
View File
@@ -55,6 +55,31 @@ module Maptool
end
end
# Ended sessions (summary["active"] == false) that ended more than
# `stale_after` seconds ago and aren't already flagged unavailable —
# i.e. ones Garmin has very likely stopped serving the live-track page
# for, but that haven't been confirmed yet (see app.rb's startup
# check). Excludes already-flagged ones so that check doesn't re-hit
# Garmin, on every restart, for a session it already told us is gone.
def stale_ended(stale_after)
cutoff = Time.now.utc - stale_after
list.select { |s| stale_ended?(s, cutoff) }
end
# Flags a session's live-track page as no longer served by Garmin, once
# confirmed (see app.rb's startup check) — the summary itself (small,
# and a record of the activity, see the class comment) is left alone.
def mark_unavailable(session_id)
@mutex.synchronize do
sessions = read
session = sessions.find { |s| s["id"] == session_id }
return unless session
session["map_available"] = false
write(sessions)
end
end
# Most recently received first.
def list
prune(read)
@@ -77,6 +102,20 @@ module Maptool
Time.now.utc # malformed/missing timestamp: don't let it block pruning
end
def stale_ended?(session, cutoff)
summary = session["summary"]
return false unless summary && summary["active"] == false && session["map_available"] != false
ended = ended_at(summary)
ended && ended < cutoff
end
def ended_at(summary)
Time.parse(summary["end"])
rescue ArgumentError, TypeError
nil # malformed/missing "end": can't tell how long it's been, so don't guess
end
def write(sessions)
File.write(@path, JSON.pretty_generate(sessions))
end