]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Flush and refresh to read the finished timestamp
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 17:52:05 +0000 (17:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 17:52:05 +0000 (17:52 +0000)
This feels like a stupid hack but this at least prevents utter mayhem
happening after this.

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

index 8238d25f2c33845df01431384344b1249e4523fa..cb0173a56be5d38e07b9832d5899818991bfb47c 100644 (file)
@@ -426,6 +426,26 @@ class Connection(object):
                # Commit!
                await session.commit()
 
+       async def flush(self, *objects):
+               """
+                       Manually triggers a flush
+               """
+               # Fetch our session
+               session = await self.session()
+
+               # Flush!
+               await session.flush(objects)
+
+       async def refresh(self, o):
+               """
+                       Refreshes the given object
+               """
+               # Fetch our session
+               session = await self.session()
+
+               # Refresh!
+               await session.refresh(o)
+
 
 class BackendMixin:
        @functools.cached_property
index 008d2bf1af5106a7c690dadb3b9e76fbdb650e23..a34d0799d382c6d02be901df09a3db7f37ce0d2c 100644 (file)
@@ -666,6 +666,13 @@ 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)
+
                # Import log
                if logfile:
                        await self._import_logfile(logfile)
@@ -747,13 +754,10 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                """
                        Returns True if this job has finished, been aborted, etc.
                """
-               # This check is checking if finished_at is set because SQLAlchemy is behaving
-               # a little bit stupid when we set finished_at to sqlalchemy.func.current_timestamp()
-               # because since this is a server function, it cannot know the value before we commit.
-               if self.finished_at is None:
-                       return False
+               if self.finished_at:
+                       return True
 
-               return True
+               return False
 
        # Failed