mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 19:56:18 -04:00
Add OpenF1 request pacing, 429 retry, and hub completeness guard
Concurrent fan-outs could burst past the free-tier rate limit; callers swallowed the 429s as missing data, and the championship hub cached the resulting partial season for its full TTL (observed live: 8 of 22 rounds, zero wins/podiums/form). - requestPacer spaces live requests (350ms anonymous, 100ms with key); cache hits never wait - get() retries 429s up to 3 times honouring Retry-After (capped 10s) - hub tracks per-meeting fetch failures and caches incomplete aggregates for only 2 minutes instead of 15min/24h Verified against the live API: 2026 hub now reports all 22 rounds with wins/podiums/form populated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -230,8 +230,8 @@ func TestChampHubCache(t *testing.T) {
|
||||
t.Fatal("empty cache should miss")
|
||||
}
|
||||
|
||||
c.put(2026, champHubResponse{Season: 2026, Round: 10}, now)
|
||||
c.put(2024, champHubResponse{Season: 2024, Round: 24}, now)
|
||||
c.put(2026, champHubResponse{Season: 2026, Round: 10}, now, champHubTTL(2026, now))
|
||||
c.put(2024, champHubResponse{Season: 2024, Round: 24}, now, champHubTTL(2024, now))
|
||||
|
||||
// Current-year entry: hit within 15 min, miss after.
|
||||
if resp, ok := c.get(2026, now.Add(14*time.Minute)); !ok || resp.Round != 10 {
|
||||
@@ -250,8 +250,17 @@ func TestChampHubCache(t *testing.T) {
|
||||
}
|
||||
|
||||
// Re-put refreshes the entry.
|
||||
c.put(2026, champHubResponse{Season: 2026, Round: 11}, now.Add(20*time.Minute))
|
||||
c.put(2026, champHubResponse{Season: 2026, Round: 11}, now.Add(20*time.Minute), champHubTTL(2026, now))
|
||||
if resp, ok := c.get(2026, now.Add(30*time.Minute)); !ok || resp.Round != 11 {
|
||||
t.Errorf("refreshed entry = (%+v, %v), want hit with Round 11", resp, ok)
|
||||
}
|
||||
|
||||
// Incomplete aggregates get the short TTL: hit right away, gone in 3 min.
|
||||
c.put(2023, champHubResponse{Season: 2023, Round: 5}, now, champHubIncompleteTTL)
|
||||
if _, ok := c.get(2023, now.Add(time.Minute)); !ok {
|
||||
t.Error("incomplete entry should hit within its short TTL")
|
||||
}
|
||||
if _, ok := c.get(2023, now.Add(3*time.Minute)); ok {
|
||||
t.Error("incomplete entry should expire after champHubIncompleteTTL")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user