From: Michael Tremer Date: Wed, 5 Feb 2025 15:49:01 +0000 (+0000) Subject: messages: Ensure we commit to the database after each message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa548f931516265714835a97e69976272c976df1;p=pbs.git messages: Ensure we commit to the database after each message We have this weird problem that after any background tasks, SQLAlchemy won't automatically commit. Therefore all those changes were lost. But since we want to avoid sending messages again if something else later in a batch fails we will commit any changes immediately after each message has been sent. Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/messages.py b/src/buildservice/messages.py index b5d8249f..796ffa40 100644 --- a/src/buildservice/messages.py +++ b/src/buildservice/messages.py @@ -285,7 +285,7 @@ class Queue(base.Object): async with self._send_lock: while True: - messages = self.get_messages(limit=1) + messages = self.get_messages() # If there are no messages left, we can quit if not messages: @@ -297,8 +297,11 @@ class Queue(base.Object): # Send the messages one by one async for message in messages: - async with await self.db.transaction(): - await self._send(relay, message, **kwargs) + # Send the message + await self._send(relay, message, **kwargs) + + # Commit to the database after each message + await self.db.commit() log.debug("All messages sent")