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>
"""
Queues and delivers any emails
"""
- def get_messages(self, limit=None):
+ async def get_messages(self, limit=None):
stmt = (
sqlalchemy
.select(
.limit(limit)
)
- return self.db.fetch(stmt)
+ return await self.db.fetch_as_list(stmt)
async def enqueue(self, message, priority=0):
"""
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: