From: Michael Tremer Date: Tue, 4 Feb 2025 14:07:59 +0000 (+0000) Subject: jobs: Rename the finished handler X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9978e1f67021c37de906ca706abe62213fd9cdd;p=pbs.git jobs: Rename the finished handler Signed-off-by: Michael Tremer --- diff --git a/src/web/__init__.py b/src/web/__init__.py index f341c911..3f976c67 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -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), diff --git a/src/web/jobs.py b/src/web/jobs.py index 6c609a40..973e1557 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -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