clone

a desktop tv and program guide for over-the-air broadcasts: what's on air, what your tuner gets, live tv, recordings

Update the listings about a day apart

FelineStateMachine committed 3db2cfb
The next update was the server's minute of the day after a full day had
passed, which could leave nearly two days between updates when that
minute came just before the last one. It's now that minute at least half
a day after the last update: 12 to 36 hours apart, a day on average.
commit
3db2cfbc48cb9aa6f9df3c25c22df79df0483904
parent
1cf22a2fe329ba6a71a6fc84927e85c0317b95a9
author
FelineStateMachine <226808055+FelineStateMachine@users.noreply.github.com>
kind
fix risk score 1.8 of 3, Jev's estimate
3 files changed, +12 -11
MREADME.md2+-
Minternal/sd/sd_test.go2+-
Minternal/sd/source.go19++++++++++---------
M README.md +1 -1
M internal/sd/sd_test.go +1 -1
M internal/sd/source.go +10 -9
@@ -184,9 +184,9 @@ func (s *Source) Kick() {
184184 }185185 }186186 187-// Run keeps the listings up to date until ctx ends: once a day, at a time188-// of its own (Schedules Direct asks clients not to all come at once), and189-// on Kick. After a failure it tries again in an hour; a refused account187+// Run keeps the listings up to date until ctx ends: about once a day, at188+// a minute of its own (Schedules Direct asks clients not to all come at189+// once), and on Kick. After a failure it tries again in an hour; a refused account190190 // stops it until the account changes.191191 func (s *Source) Run(ctx context.Context) {192192 s.init()
@@ -200,15 +200,16 @@ func (s *Source) Run(ctx context.Context) {
200200 stopped, updated := s.st.Stopped, s.st.Updated201201 s.mu.Unlock()202202 if stopped == "" {203- due := updated.Add(24 * time.Hour)204- if updated.IsZero() || !time.Now().Before(due) {203+ // The server's own minute of the day, at least half a day204+ // after the last update: a day apart, give or take.205+ soonest := updated.Add(12 * time.Hour)206+ if next = soonest.Truncate(24 * time.Hour).Add(offset); next.Before(soonest) {207+ next = next.Add(24 * time.Hour)208+ }209+ if updated.IsZero() || !time.Now().Before(next) {205210 s.update(ctx, a)206211 continue207212 }208- // The server's own minute of the day, once a day has passed.209- if next = due.Truncate(24 * time.Hour).Add(offset); next.Before(due) {210- next = next.Add(24 * time.Hour)211- }212213 }213214 }214215 s.mu.Lock()