import logging
import os.path
import psutil
+import tornado.escape
import tornado.httpclient
import tornado.websocket
import urllib.parse
return
return callback(message)
+
+ async def job(self, id):
+ """
+ Connects to the given job
+ """
+ # Connect to the hub
+ conn = await self._request("GET", "/jobs/%s/builder" % id,
+ websocket=True, ping=10)
+
+ # Return a Job proxy
+ return Job(self, id, conn)
+
+
+class Job(object):
+ """
+ Proxy for Build Jobs
+ """
+ def __init__(self, hub, id, conn):
+ self.hub = hub
+ self.id = id
+ self.conn = conn
+
+ async def _write_message(self, message, **kwargs):
+ """
+ Sends a message but encodes it into JSON first
+ """
+ if isinstance(message, dict):
+ message = tornado.escape.json_encode(message)
+
+ return await self.conn.write_message(message, **kwargs)
+
+ async def status(self, status):
+ """
+ Sends a new status to the hub
+ """
+ await self._write_message({
+ "message" : "status",
+ "status" : status,
+ })
+
+ async def log(self, level, message):
+ """
+ Sends a log message to the hub
+ """
+ await self._write_message({
+ "message" : "log",
+ "level" : level,
+ "log" : message,
+ })