From 2dc6117bd7852938fd6da1cc5feba5f14243b56c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 23 Oct 2022 20:54:05 +0000 Subject: [PATCH] daemon: Call the finished handler after a job has finished Signed-off-by: Michael Tremer --- src/pakfire/daemon.py | 22 +++++++++++++++------- src/pakfire/hub.py | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index c6924c05f..5690257af 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -208,6 +208,8 @@ class Worker(multiprocessing.Process): """ Called from the async IO loop doing all the work """ + success = False + # Extract the job id job_id = self.data.get("id") if not job_id: @@ -234,9 +236,6 @@ class Worker(multiprocessing.Process): # Setup build logger logger = BuildLogger(self.log, self.job) - # Send a new status - await self.job.status("building") - # Run the build try: build = self._build(pkg, arch=arch, @@ -246,11 +245,20 @@ class Worker(multiprocessing.Process): while not build.done(): await logger.stream(timeout=1) + # Catch any other Exception + except Exception as e: + raise e + + # The build has finished successfully + else: + success = True + + # Notify the hub that the job has finished finally: - # Upload the build log - log_upload_id = await self.hub.upload( - logger.logfile.name, - filename="%s.log" % job_id, + await self.hub.finish_job( + job_id, + success=success, + log=logger.logfile.name, ) def _build(self, pkg, arch=None, logger=None, **kwargs): diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index 79d5341fa..d14ac089e 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -438,6 +438,21 @@ class Hub(object): # Return a Job proxy return Job(self, id, conn) + async def finish_job(self, job_id, success, log): + """ + Will tell the hub that a job has finished + """ + # Upload the log file + if log: + log = await self.upload(log, filename="%s.log" % job_id) + + # Send the request + response = await self._request("POST", "/jobs/%s/finished" % job_id, + success=success, log=log) + + # Handle the response + # XXX TODO + class Job(object): """ -- 2.39.5