(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.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),
# Setup logging
log = logging.getLogger("pbs.web.jobs")
-class APIv1ControlHandler(base.APIMixin, base.BackendMixin, tornado.websocket.WebSocketHandler):
- """
- Builders connect to this handler when they are running a build.
-
- We can pass information about this build around in real time.
- """
- # Don't allow users to authenticate
- allow_users = False
-
- @base.negotiate
- async def open(self, job_id):
- self.job = await self.backend.jobs.get_by_uuid(job_id)
- if not self.job:
- raise tornado.web.HTTPError(404, "Could not find job %s" % job_id)
-
- # Check permissions
- if not self.job.has_perm(self.current_user):
- raise tornado.web.HTTPError(403, "%s cannot control job %s" \
- % (self.current_user, self.job))
-
- # Consider the job connected
- self.job.connected(self)
-
- # Open a new log stream
- self.logstream = self.backend.logstreams.open(self.job)
-
- def on_close(self):
- # Drop the connection to the builder
- self.job.disconnected()
-
- # Close the logstream
- self.logstream.close()
-
- async def on_message(self, message):
- message = self._decode_json_message(message)
-
- # Get message type & data
- type = message.get("type")
- data = message.get("data")
-
- # Handle log messages
- if type == "log":
- await self._handle_log(**data)
-
- # Unknown message
- else:
- log.warning("Received a message of an unknown type: %s" % t)
-
- async def _handle_log(self, timestamp=None, level=None, message=None, **kwargs):
- """
- Called when a new log message has been received
- """
- await self.logstream.message(timestamp, level, message)
-
-
class APIv1IndexHandler(base.APIMixin, tornado.web.RequestHandler):
@base.negotiate
async def post(self, uuid):