From: Michael Tremer Date: Thu, 13 Oct 2022 15:38:14 +0000 (+0000) Subject: jobs: Propagate to the build that a job has finished X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e416b831f4c95d6f40e735e2cb6637191bc932b6;p=pbs.git jobs: Propagate to the build that a job has finished Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 6747fdea..5df2ec9c 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -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 = [] diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 4ae6c8dc..03328a69 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -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): """