]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Call the finished handler after a job has finished
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 20:54:05 +0000 (20:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 20:54:05 +0000 (20:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.py
src/pakfire/hub.py

index c6924c05f2807751e508ed8430dcd7d5e5fd27d2..5690257af5dfcecde69acede99c67a605138cfab 100644 (file)
@@ -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):
index 79d5341fa381ba56fc550ad42775ba826180a58f..d14ac089e2be4dc6c1115fb7dbff5b84101e4db4 100644 (file)
@@ -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):
        """