]> git.ipfire.org Git - pbs.git/commitdiff
builds: Add a combined operation to flush and refresh
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 20:30:27 +0000 (20:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 20:30:27 +0000 (20:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/buildservice/database.py
src/buildservice/jobs.py

index 113b57ead2ed0154767a4b6a3add64207a5e3cf6..c55263d408e2562316cbb66c76ad2d645aa18ea4 100644 (file)
@@ -699,6 +699,9 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                # Mark as finished
                self.finished_at = sqlalchemy.func.current_timestamp()
 
+               # Flush and refresh
+               await self.db.flush_and_refresh(self)
+
                # Mark as failed if the build was not successful
                if not success:
                        self.failed = True
index cb0173a56be5d38e07b9832d5899818991bfb47c..d5ac2d614c3f0b09c1b0ec10c099a4b9353ce22d 100644 (file)
@@ -446,6 +446,20 @@ class Connection(object):
                # Refresh!
                await session.refresh(o)
 
+       async def flush_and_refresh(self, *objects):
+               """
+                       Flushes and refreshes in one go.
+               """
+               # Fetch our session
+               session = await self.session()
+
+               # Flush!
+               await session.flush(objects)
+
+               # Refresh!
+               for o in objects:
+                       await session.refresh(o)
+
 
 class BackendMixin:
        @functools.cached_property
index 57e757ef5b314a72d787bc9630fc18cf1747de97..239cd2f602dec558fe17400d4c25000769487929 100644 (file)
@@ -664,12 +664,8 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                # Store the time
                self.finished_at = sqlalchemy.func.current_timestamp()
 
-               # Flush to the database
-               await self.db.flush(self)
-
-               # Read back the timestamp so that we won't trigger
-               # a read from synchronous code later.
-               await self.db.refresh(self)
+               # Flush to the database and read back the timestamp
+               await self.db.flush_and_refresh(self)
 
                # Import log
                if logfile: