]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Propagate to the build that a job has finished
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Oct 2022 15:38:14 +0000 (15:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 Oct 2022 15:38:14 +0000 (15:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/buildservice/jobs.py

index 6747fdeae61dc97f48d4c7fa1007f46fb7f62e12..5df2ec9cefdf7fd5b023125e73b245f3d346af71 100644 (file)
@@ -414,6 +414,8 @@ class Build(base.DataObject):
        def supported_arches(self):
                return self.pkg.supported_arches
 
+       # Jobs
+
        def _get_jobs(self, query, *args):
                ret = []
                for job in self.backend.jobs._get_jobs(query, *args):
@@ -435,17 +437,6 @@ class Build(base.DataObject):
                return self._get_jobs("SELECT * FROM jobs \
                        WHERE build_id = %s AND test IS TRUE", self.id)
 
-       @property
-       def all_jobs_finished(self):
-               ret = True
-
-               for job in self.jobs:
-                       if not job.state == "finished":
-                               ret = False
-                               break
-
-               return ret
-
        def _create_jobs(self):
                """
                        Called after a build has been created and creates all jobs
@@ -474,6 +465,24 @@ class Build(base.DataObject):
                for arch in arches:
                        self.backend.jobs.create(self, arch)
 
+       async def _job_finished(self, job):
+               """
+                       Called when a job finished.
+
+                       This function will determine the status of the build and run and actions.
+               """
+               # Nothing to do, if this build has already finished
+               if self.has_finished():
+                       return
+
+               # If all jobs have finished, the build has finished
+               elif all((j.has_finished() for j in self.jobs)):
+                       return await self.finished()
+
+               # If there are any failed jobs, the build has failed
+               elif any((j.has_failed() for j in self.jobs)):
+                       return await self.failed()
+
        ## Comment stuff
 
        def comment(self, *args, **kwargs):
@@ -590,6 +599,29 @@ class Build(base.DataObject):
 
                # XXX add any permanent watchers
 
+       # Actions
+
+       async def finished(self):
+               """
+                       Called when this build has successfully finished
+               """
+               pass # XXX TODO
+
+       def has_finished(self):
+               """
+                       Returns True if this build has finished
+               """
+               if self.finished_at:
+                       return True
+
+               return False
+
+       async def failed(self):
+               """
+                       Called when the build has failed
+               """
+               pass # XXX TODO
+
        @property
        def message_recipients(self):
                ret = []
index 4ae6c8dc366e6c6ccc748293c1988377677cc68c..03328a69db2f9130537e515d0ec5fa11fa50fdc1 100644 (file)
@@ -273,7 +273,8 @@ class Job(base.DataObject):
                        if self.owner:
                                self.owner.send_message("jobs/messages/failed.txt", job=self)
 
-               # XXX propagate any changes to the build
+               # Propagate any changes to the build
+               await self.build._job_finished(job=self)
 
        def is_running(self):
                """