Skip to content

Commit

Permalink
quality: Enhance code quality for queues
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Oct 10, 2024
1 parent 0e00615 commit 73fd7b6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/persistence/azure_queue_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,27 @@ async def trigger(
arg: str,
func: Callable[..., Awaitable],
):
"""
Trigger a local function when a message is received.
"""
logger.info(
'Azure Queue Storage "%s" is set to trigger function "%s"',
self._name,
func.__name__,
)
# Loop forever to receive messages
while messages := self.receive_messages(
max_messages=32,
visibility_timeout=32 * 5, # 5 secs per message
):
# Process messages
async for message in messages:
# Call function with the selected argument name
kwargs = {}
kwargs[arg] = message
# First, call function
await func(**kwargs)
# Then, delete message
await self.delete_message(message)
await asyncio.sleep(1) # Add a small delay to avoid tight loop
# Add a small delay to avoid tight loop
await asyncio.sleep(1)

0 comments on commit 73fd7b6

Please sign in to comment.