Skip to content

Commit

Permalink
Refresh task queue first before get task from queue
Browse files Browse the repository at this point in the history
This allows relinquishing control to the event loop to ensure requeueing
coroutines have the chance to get run before another task is fetched
from the queue.
  • Loading branch information
unkcpz authored and sphuber committed Dec 2, 2024
1 parent ece863e commit 2434b44
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/kiwipy/rmq/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ async def next_task(self,
raises:
kiwipy.exceptions.QueueEmpty: When the queue has no tasks within the timeout
"""
# relinquish so that if there is requeue coroutines, they are run first and task queue get updated
await asyncio.sleep(0)

try:
message = await self._task_queue.get(no_ack=no_ack, fail=fail, timeout=timeout)
except aio_pika.exceptions.QueueEmpty as exc:
Expand Down

0 comments on commit 2434b44

Please sign in to comment.