]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Rename the finished handler
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Feb 2025 14:07:59 +0000 (14:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Feb 2025 14:07:59 +0000 (14:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/__init__.py
src/web/jobs.py

index f341c9113aa7978127ea5c8115e9db965046b99c..3f976c6715317e28fd7bc943510a14038e1cdf6c 100644 (file)
@@ -114,9 +114,10 @@ class Application(tornado.web.Application):
                        (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/abort", jobs.AbortHandler),
                        (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/log", jobs.LogHandler),
                        (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/retry", jobs.RetryHandler),
-                       (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})/finished",
+                               jobs.APIv1FinishedHandler),
                        (r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/log/stream",
                                jobs.APIv1LogStreamHandler),
 
index 6c609a402a13304a16a9e85d90c59ed8f18a56a3..973e15577f70eceb724e1d23123afc422c0d0c5b 100644 (file)
@@ -10,7 +10,7 @@ from . import base
 # Setup logging
 log = logging.getLogger("pbs.web.jobs")
 
-class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler):
+class APIv1FinishedHandler(base.APIMixin, base.BackendMixin, tornado.web.RequestHandler):
        @base.negotiate
        async def post(self, uuid):
                job = await self.backend.jobs.get_by_uuid(uuid)
@@ -19,21 +19,28 @@ class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler):
 
                # Check permissions
                if not job.has_perm(self.current_user):
-                       raise tornado.web.HTTPError(403, "%s cannot edit job %s" % (self.current_user, job))
+                       raise tornado.web.HTTPError(403)
 
                # Success Status
                success = self.get_argument_bool("success")
 
                # Fetch the logfile
-               logfile = self.get_argument_upload("logfile")
+               logfile = await self.get_argument_upload("logfile")
 
                # Fetch the packages
-               packages = self.get_argument_uploads("packages")
+               packages = await self.get_argument_uploads("packages")
 
                # Mark the job as finished
-               with self.db.transaction():
-                       builds = await job.finished(success=success,
-                               logfile=logfile, packages=packages)
+               async with await self.db.transaction():
+                       builds = await job.finished(
+                               success  = success,
+                               logfile  = logfile,
+                               packages = packages,
+                       )
+
+               # Send an empty response
+               self.set_status(204)
+               self.finish()
 
                # Try to dispatch the next job
                await self.backend.jobs.queue.dispatch()
@@ -42,9 +49,6 @@ class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler):
                if builds:
                        self.backend.run_task(self.backend.builds.launch, builds)
 
-               # Send something back to the builder
-               self.finish({})
-
 
 class APIv1LogStreamHandler(base.BackendMixin, tornado.websocket.WebSocketHandler):
        # No authentication required