]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Add crash handler
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 17:26:52 +0000 (17:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 17:26:52 +0000 (17:26 +0000)
This will be called by the builders when the build process has
unexexpectedly crashed.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/__init__.py
src/web/jobs.py

index 9d6f6492bca9bc955fce5ff846ebb0abf2410bd0..65d3f8f4bd1aef9e885e1a755b368668483a862e 100644 (file)
@@ -117,6 +117,8 @@ class Application(tornado.web.Application):
                        (r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})",
                                jobs.APIv1ControlHandler),
                        (r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", jobs.APIv1IndexHandler),
+                       (r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/crashed",
+                               jobs.APIv1CrashedHandler),
                        (r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/log/stream",
                                jobs.APIv1LogStreamHandler),
 
index 3fb1d5889573e05dab0ae1ab9c2be90b23245199..05f69ffc023a50d748fdf925326e76368acaefb3 100644 (file)
@@ -137,6 +137,35 @@ class APIv1LogStreamHandler(base.BackendMixin, tornado.websocket.WebSocketHandle
                        pass
 
 
+class APIv1CrashedHandler(base.APIMixin, base.BackendMixin):
+       """
+               This handler is called by the daemon when a job has crashed.
+       """
+       # Don't allow users to authenticate
+       allow_users = False
+
+       @base.negotiate
+       async def post(self, job_id):
+               job = await self.backend.jobs.get_by_uuid(job_id)
+               if not job:
+                       raise tornado.web.HTTPError(404, "Could not find job %s" % job_id)
+
+               # Check permissions
+               if not job.has_perm(self.current_user):
+                       raise tornado.web.HTTPError(403)
+
+               # Signal
+               signo = self.get_argument_int("signo")
+
+               log.error("%s has been killed with signal %s" % (job, signo))
+
+               # XXX TODO
+
+               # Send an empty response
+               self.set_status(204)
+               self.finish()
+
+
 class IndexHandler(base.BaseHandler):
        async def get(self):
                # Pagination