]> git.ipfire.org Git - pbs.git/commitdiff
messages: Fetch messages in badges
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 16:20:19 +0000 (16:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 16:20:19 +0000 (16:20 +0000)
We would have otherwise looped for forever since we cannot check in
advance whether the iterator actually has any elements, but we don't
want to connect to the mail relay if there is literally nothing to send.
So as a compromise we fetch messages in batches.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/messages.py

index 796ffa40679a5f2faad530c1aa5a9fa437bf5345..7fabab543a117dd0625012f9a6aec08f2649428b 100644 (file)
@@ -230,7 +230,7 @@ class Queue(base.Object):
        """
                Queues and delivers any emails
        """
-       def get_messages(self, limit=None):
+       async def get_messages(self, limit=None):
                stmt = (
                        sqlalchemy
                        .select(
@@ -246,7 +246,7 @@ class Queue(base.Object):
                        .limit(limit)
                )
 
-               return self.db.fetch(stmt)
+               return await self.db.fetch_as_list(stmt)
 
        async def enqueue(self, message, priority=0):
                """
@@ -285,7 +285,7 @@ class Queue(base.Object):
 
                async with self._send_lock:
                        while True:
-                               messages = self.get_messages()
+                               messages = await self.get_messages(limit=10)
 
                                # If there are no messages left, we can quit
                                if not messages: