Repository navigation
Don't miss queue changes announced while the worker polls queues - #101
luca-montaigut wants to merge 1 commit into
Conversation
_maintain_queues listened for queue.declared/paused/resumed only while inside hub.wait_for(). An event emitted while it was reading the queues from the database had no waiter and was dropped, so the change was only seen at the next queue_change_poll_interval (10s by default). Record these events in an asyncio.Event set by a hub handler, cleared before each poll, the same way queue.pushed already wakes queues through queue_wake_events. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 26_ux #101 +/- ##
==========================================
+ Coverage 67.44% 67.52% +0.08%
==========================================
Files 62 62
Lines 3781 3788 +7
==========================================
+ Hits 2550 2558 +8
+ Misses 1231 1230 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Closing this, sorry for the noise. I was investigating the intermittent One observation, in case it helps: in the failing |
|
Thanks for taking a look either way! I've been reworking the fixtures which should outright make these issues impossible within the trivial tests. For the most part the tests are just too down-to-the-second with timeouts and the github workers can be incredibly slow. |
The worker sometimes misses a
queue.declared/queue.paused/queue.resumednotification and only sees the change at the nextqueue_change_poll_interval(10s by default). This is probably whytest_regression_48_eagerstill fails intermittently on #58.The problem
_maintain_queuesloops:await self.hub.wait_for([...], timeout=queue_change_poll_interval);Hub.wait_for()registers its waiters when it is called and drops them when it returns, andHub.emit()only reaches the waiters registered at that moment. If the notification arrives during step 1, nothing is waiting for it and it is lost. The worker then sleeps the full 10s before polling again.On #58's last run (
ubuntu-24.04 - Py3.14 - Django5.2 - PG14), theeagerqueue is declared at 09:32:34 and the worker logsAdding queue 'eager'at 09:32:44: exactly one poll interval later, with the test'swait_for_jobs(..., timeout=10)already used up.The fix
The same pattern the worker already uses for
queue.pushed: there,_handle_queue_pushedsetsqueue_wake_events[q]and the queue loop waits on that event. Here:_handle_queues_changedhub handler, registered instart()for the three events, setsself._queues_changed;_maintain_queuesclears it right before reading the queues, then waits on it, with the samequeue_change_poll_intervaltimeout, instead of onhub.wait_for().A change announced during the poll leaves the event set, so the next wait returns immediately. The 10s poll is still there as a fallback for notifications that never arrive.
Testing
test_queue_declared_during_poll_is_not_missed. It holds the worker right after it has read the queues, declares a queue, waits until the notification has reached the worker's hub, then checks the queue is picked up within 3s. It fails every time without the fix and passes in about 0.2s with it.To be clear about what this proves: the new test shows the lost wakeup and that the fix closes it. I could not make
test_regression_48_eageritself fail locally, before or after the fix. The link to the failure on #58 rests on the 10s gap in the CI log above.🤖 Generated with Claude Code