raise ValueError("Did not received a package URL")
# Connect to the hub
- self.job = await self.hub.job(job_id)
+ self.job = await self.hub.job(job_id, abort_callback=self.abort)
# Setup build logger
logger = BuildLogger(self.log, self.job)
# XXX figure out what to do, when a build is running
+ def abort(self, *args, **kwargs):
+ """
+ Called to abort a running build immediately
+ """
+ log.warning("Build job has been aborted")
+
+ # XXX TODO
+
# Signal handling.
def register_signal_handlers(self):
"""
return await self._proxy(ControlConnection, *args, **kwargs)
- async def job(self, job_id):
+ async def job(self, *args, **kwargs):
"""
Creates a control connection for a certain job
"""
- return await self._proxy(JobControlConnection, job_id)
+ return await self._proxy(JobControlConnection, *args, **kwargs)
class HubObject(object):
"""
Proxy for Build Jobs
"""
- def init(self, id):
+ def init(self, id, abort_callback=None):
self.id = id
+ self.callbacks = {
+ "abort" : abort_callback,
+ }
+
@property
def url(self):
return "/api/v1/jobs/%s" % self.id
+ def on_message_callback(self, message):
+ message = self.hub._decode_json_message(message)
+
+ # Ignore empty messages
+ if message is None:
+ return
+
+ # Log the received message
+ log.debug("Received message:\n%s" % json.dumps(message, indent=4))
+
+ # Fetch the message type & data
+ type = message.get("type")
+ data = message.get("data")
+
+ # Find a suitable callback
+ try:
+ callback = self.callbacks[type]
+
+ # Log an error for unknown messages and ignore them
+ except KeyError:
+ log.error("Received message of unknown type '%s'" % type)
+ return
+
+ # Call the callback
+ callback(data)
+
async def finished(self, success, packages=None, logfile=None):
"""
Will tell the hub that a job has finished