]> git.ipfire.org Git - pbs.git/commitdiff
messages: Ensure we commit to the database after each message
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 15:49:01 +0000 (15:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 15:49:01 +0000 (15:49 +0000)
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 <michael.tremer@ipfire.org>
src/buildservice/messages.py

index b5d8249fb391aea4ed58107ba0e6253afa463cb4..796ffa40679a5f2faad530c1aa5a9fa437bf5345 100644 (file)
@@ -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")