From: Michael Tremer Date: Wed, 3 May 2023 15:45:38 +0000 (+0000) Subject: builds/jobs: Launch them only after the db transaction as been committed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adaaf5fcf26d2eea9ab25de6e47340cd8b9e604d;p=pbs.git builds/jobs: Launch them only after the db transaction as been committed Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 060a9656..1e028010 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -249,6 +249,14 @@ class Builds(base.Object): return build + async def launch(self, builds): + """ + Called to launch all given builds + """ + # Launch all jobs + for build in builds: + await self.backend.jobs.launch(build.jobs) + # Groups @lazy_property diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 092033a3..f865ba77 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -93,7 +93,7 @@ class Jobs(base.Object): return list(jobs) - async def launch(self, *jobs): + async def launch(self, jobs): """ Called to launch all given jobs """ @@ -465,7 +465,7 @@ class Job(base.DataObject): ) # Propagate any changes to the build - await self.build._job_finished(job=self) + return await self.build._job_finished(job=self) def is_pending(self): if self.has_finished(): @@ -600,10 +600,7 @@ class Job(base.DataObject): raise RuntimeError("Job %s cannot be retried" % self) # Clone the job - job = self.clone() - - # Launch the newly created job - self.backend.run_task(self.backend.jobs.launch, job) + return self.clone() # Log diff --git a/src/scripts/pakfire-build-service b/src/scripts/pakfire-build-service index d3b89ff5..331bfd5d 100644 --- a/src/scripts/pakfire-build-service +++ b/src/scripts/pakfire-build-service @@ -157,7 +157,10 @@ class Cli(object): continue with self.backend.db.transaction(): - await build.create_test_builds() + builds = await build.create_test_builds() + + # Launch all builds + await self.backend.builds.launch(builds) async def main(): diff --git a/src/web/builds.py b/src/web/builds.py index 6220a55b..ff1694d8 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -53,7 +53,7 @@ class APIv1IndexHandler(base.APIMixin, base.BaseHandler): }) # Launch all jobs (in the background) - self.backend.run_task(self.backend.jobs.launch, *build.jobs) + self.backend.run_task(self.backend.builds.launch, [build]) class IndexHandler(base.BaseHandler): diff --git a/src/web/jobs.py b/src/web/jobs.py index 5dece721..2811917c 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -82,11 +82,16 @@ class APIv1DetailHandler(base.APIMixin, tornado.websocket.WebSocketHandler): # Mark the job as finished with self.db.transaction(): - await self.job.finished(success=success, logfile=logfile, packages=packages) + builds = await self.job.finished(success=success, + logfile=logfile, packages=packages) # Try to dispatch the next job self.backend.run_task(self.backend.jobs.queue.dispatch) + # Launch any (test) builds + if builds: + self.backend.run_task(self.backend.builds.launch, builds) + class APIv1LogStreamHandler(base.BackendMixin, tornado.websocket.WebSocketHandler): # No authentication required @@ -226,7 +231,10 @@ class RetryHandler(base.BaseHandler): raise tornado.web.HTTPError(404, "Could not find job %s" % uuid) with self.db.transaction(): - await job.retry(self.current_user) + job = await job.retry(self.current_user) + + # Launch the newly created job + self.backend.run_task(self.backend.jobs.launch, [job]) # Redirect back to the build page self.redirect("/builds/%s" % job.build.uuid)