(r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/retry", jobs.RetryHandler),
(r"/job/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/buildroot", jobs.JobBuildrootHandler),
(r"/api/v1/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})",
- jobs.APIv1DetailHandler),
+ jobs.APIv1ControlHandler),
+ (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),
# Setup logging
log = logging.getLogger("pbs.web.jobs")
-class APIv1DetailHandler(base.APIMixin, tornado.websocket.WebSocketHandler):
+class APIv1ControlHandler(base.APIMixin, tornado.websocket.WebSocketHandler):
"""
Builders connect to this handler when they are running a build.
if type == "log":
await self._handle_log(**data)
- # Handle finished message
- elif type == "finished":
- await self._handle_finished(**data)
-
# Unknown message
else:
log.warning("Received a message of an unknown type: %s" % t)
"""
await self.logstream.message(timestamp, level, message)
- async def _handle_finished(self, success=False, logfile=None, packages=[], **kwargs):
- """
- Called when a job has finished - whether successfully or not
- """
- # Fetch the log
- if logfile:
- logfile = self.backend.uploads.get_by_uuid(logfile)
+
+class APIv1FinishedHandler(base.APIMixin, tornado.web.RequestHandler):
+ @tornado.web.authenticated
+ async def post(self, uuid):
+ job = self.backend.jobs.get_by_uuid(uuid)
+ if not job:
+ raise tornado.web.HTTPError(404, "Could not find job %s" % uuid)
+
+ # Check permissions
+ if not job.has_perm(self.current_user):
+ raise tornado.web.HTTPError(403, "%s cannot edit job %s" % (self.current_user, job))
+
+ # Success Status
+ success = self.get_argument_bool("success")
+
+ # Fetch the logfile
+ logfile = self.get_argument_upload("logfile")
# Fetch the packages
- if packages:
- packages = [self.backend.uploads.get_by_uuid(p) for p in packages]
+ packages = self.get_argument_uploads("packages")
# Mark the job as finished
with self.db.transaction():
- builds = await self.job.finished(success=success,
+ builds = await job.finished(success=success,
logfile=logfile, packages=packages)
# Try to dispatch the next job
if builds:
self.backend.run_task(self.backend.builds.launch, builds)
+ # Send something back to the builder
+ self.finish({
+ "status" : "ok",
+ })
+
class APIv1LogStreamHandler(base.BackendMixin, tornado.websocket.WebSocketHandler):
# No authentication required