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
| M | README.md | 2 | +- |
| M | internal/ | 2 | +- |
| M | internal/ | 19 | ++++++++++--------- |
@@ -193,7 +193,7 @@ there instead: two weeks of them, with long descriptions, cast, original air dat
193193 runtimes and star ratings, and sports teams. Sign in on the admin page (Guide listings); the194194 server keeps the user name and the password's SHA-1, which is what the API takes, in195195 `<data>/schedulesdirect`, readable by it alone, and never in backups or the app. It adds the196-ZIP code's antenna lineup to the account, updates once a day at a minute of its own, asks only196+ZIP code's antenna lineup to the account, updates about once a day at a minute of its own, asks only197197 for the station-days that changed, and stops asking altogether when the account is refused198198 (a wrong password, a locked or expired account) until it's saved again, as Schedules Direct199199 requires. The app's guide still shows its listing hours; recording rules look the two weeks@@ -339,7 +339,7 @@ func TestRunOncePerDay(t *testing.T) {
339339 if n := f.count("POST schedules/md5"); n != 1 {340340 t.Fatalf("%d updates, want one", n)341341 }342- if next := s.Status().Next; time.Until(next) < 12*time.Hour {342+ if next := s.Status().Next; time.Until(next) < 11*time.Hour || time.Until(next) > 37*time.Hour {343343 t.Fatalf("next update %s", next)344344 }345345 }@@ -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()