]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Fix finishing jobs
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 16:27:17 +0000 (16:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 16:27:17 +0000 (16:27 +0000)
Obviously the database field is nullable and NULL by default.

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

index 71e07ccfd60edaca3f24fe2b9c0687c06a04f4b0..eb64a4f4b23b612ccadddb6c0b51c44b86bf9559 100644 (file)
@@ -611,7 +611,7 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
 
        # Finished At
 
-       finished_at = Column(DateTime(timezone=False), nullable=False)
+       finished_at = Column(DateTime(timezone=False))
 
        # Date
 
@@ -777,15 +777,16 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                return self.started_at and not self.finished_at and not self.aborted_at
 
        def has_finished(self):
-               # Jobs can be marked as finished
-               if self.finished_at:
-                       return True
-
-               # Jobs can be marked as aborted, too
-               elif self.aborted_at:
-                       return True
+               """
+                       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
 
-               return False
+               return True
 
        # Failed