From: Michael Tremer Date: Sun, 26 Jan 2025 17:26:52 +0000 (+0000) Subject: jobs: Add crash handler X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f25bd727cb2f0437c7aabd61fc6a20f862a3937;p=pbs.git jobs: Add crash handler This will be called by the builders when the build process has unexexpectedly crashed. Signed-off-by: Michael Tremer --- diff --git a/src/web/__init__.py b/src/web/__init__.py index 9d6f6492..65d3f8f4 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -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), diff --git a/src/web/jobs.py b/src/web/jobs.py index 3fb1d588..05f69ffc 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -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