Back off a failed Jolpica ask; render posters off the event loop
Review round 1 (two findings): - While Jolpica failed, every schedule read asked it again, up to four times per poster request, and the poster, thumb and grand-prix routes were async, so the pacing, a 429's pause and a timeout stalled every request. A failed ask is now remembered for ten minutes (the kept schedule, or none, is answered meanwhile), a schedule in memory is answered without waiting for an ask under way, and those routes are plain defs in the threadpool. A rendered picture is stored whole (written aside, then renamed), as two may now render it side by side. - Bytecode was tracked: tests/__pycache__ (added with the tests) and models/__pycache__ that the cleanup missed. Untracked; .gitignore already names __pycache__/. From the review's notes: a poster whose map or photo failed is sent with a five-minute cache instead of a year's; uvicorn trusts the proxy's forwarded headers, so /examples redirects to https, not http; stale comments naming CARTO and the zoom lookup's key are corrected. Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -24,11 +24,14 @@ class ScheduleTest(unittest.TestCase):
|
||||
service.REQUEST_INTERVAL = 0
|
||||
return service
|
||||
|
||||
def test_a_failed_fetch_is_not_kept(self):
|
||||
def test_a_failed_fetch_is_not_kept_and_not_asked_again_within_the_backoff(self):
|
||||
service = self.service()
|
||||
with mock.patch.object(service, "_ask_jolpica", side_effect=[None, RACES]) as ask:
|
||||
self.assertEqual(service._fetch_season_schedule(2019), [])
|
||||
self.assertEqual(service._fetch_season_schedule(2019), RACES)
|
||||
self.assertEqual(service._fetch_season_schedule(2019), []) # within the backoff: not asked
|
||||
self.assertEqual(ask.call_count, 1)
|
||||
service.FAILED_BACKOFF = 0
|
||||
self.assertEqual(service._fetch_season_schedule(2019), RACES) # past it: asked, and kept
|
||||
self.assertEqual(ask.call_count, 2)
|
||||
|
||||
def test_a_season_that_is_over_is_read_from_disk(self):
|
||||
|
||||
Reference in New Issue
Block a user