diff options
author | Lauren Perry <lauren.perry@codethink.co.uk> | 2015-04-10 15:29:06 +0100 |
---|---|---|
committer | Richard Ipsum <richardipsum@fastmail.co.uk> | 2015-04-29 16:11:14 +0000 |
commit | 4941d1dd806d1751b1ac0f7a695ec2b6dce93ba0 (patch) | |
tree | 0f39b69358e9af9066b9d2dbc2ceffe4eebb7cf2 /distbuild/initiator.py | |
parent | 84096556ea54d4af236f1fe5f7ccf61c1343016f (diff) | |
download | morph-4941d1dd806d1751b1ac0f7a695ec2b6dce93ba0.tar.gz |
distbuild: Add distbuild status command
Adds a command to get the status of all recently ran distbuilds
for a given server (e.g. Running, Finished, Failed, Cancelled),
so as to tell if a build running via distbuild-start has finished
or otherwise exited without going through the server's log files
Change-Id: I5ce9fe54ae7b1bd8fe3e0d629f615042be8827ed
Diffstat (limited to 'distbuild/initiator.py')
-rw-r--r-- | distbuild/initiator.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/distbuild/initiator.py b/distbuild/initiator.py index 40b56a9d..359c9dbf 100644 --- a/distbuild/initiator.py +++ b/distbuild/initiator.py @@ -431,3 +431,57 @@ class InitiatorListJobs(distbuild.StateMachine): def _terminate(self, event_source, event): self.mainloop.queue_event(self._cm, distbuild.StopConnecting()) self._jm.close() + + +class InitiatorStatus(distbuild.StateMachine): + + def __init__(self, cm, conn, app, job_id): + distbuild.StateMachine.__init__(self, 'waiting') + self._cm = cm + self._conn = conn + self._app = app + self._job_id = job_id + + def setup(self): + distbuild.crash_point() + + self._jm = distbuild.JsonMachine(self._conn) + self.mainloop.add_state_machine(self._jm) + logging.debug('initiator: _jm=%s' % repr(self._jm)) + + spec = [ + # state, source, event_class, new_state, callback + ('waiting', self._jm, distbuild.JsonEof, None, self._terminate), + ('waiting', self._jm, distbuild.JsonNewMessage, None, + self._handle_json_message), + ] + self.add_transitions(spec) + + self._app.status(msg='Requesting status of recent build requests.') + msg = distbuild.message('build-status', + id=self._job_id, + protocol_version=distbuild.protocol.VERSION, + ) + self._jm.send(msg) + logging.debug('Initiator: sent to controller: %s', repr(msg)) + + def _handle_json_message(self, event_source, event): + distbuild.crash_point() + + logging.debug('Initiator: from controller: %s', str(event.msg)) + + handlers = { + 'request-output': self._handle_request_output, + } + + handler = handlers[event.msg['type']] + handler(event.msg) + + def _handle_request_output(self, msg): + self._app.status(msg=str(msg['message'])) + self.mainloop.queue_event(self._cm, distbuild.StopConnecting()) + self._jm.close() + + def _terminate(self, event_source, event): + self.mainloop.queue_event(self._cm, distbuild.StopConnecting()) + self._jm.close() |