summaryrefslogtreecommitdiff
path: root/pygerrit/stream.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygerrit/stream.py')
-rw-r--r--pygerrit/stream.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/pygerrit/stream.py b/pygerrit/stream.py
index 7026213..c786ad0 100644
--- a/pygerrit/stream.py
+++ b/pygerrit/stream.py
@@ -9,6 +9,18 @@ from select import poll, POLLIN
from threading import Thread, Event
from pygerrit.ssh import GerritSSHClient
+from pygerrit.error import GerritError
+from pygerrit.events import GerritEvent, GerritEventFactory
+
+
+@GerritEventFactory.register("gerrit-stream-error")
+class GerritStreamErrorEvent(GerritEvent):
+
+ """ Represents an error when handling the gerrit event stream """
+
+ def __init__(self, json_data):
+ super(GerritStreamErrorEvent, self).__init__()
+ self.error = json_data["error"]
class GerritStream(Thread):
@@ -28,15 +40,20 @@ class GerritStream(Thread):
def run(self):
""" Listen to the stream and send events to the client. """
- client = GerritSSHClient(self._host)
- _stdin, stdout, _stderr = client.run_gerrit_command("stream-events")
- p = poll()
- p.register(stdout.channel)
- while not self._stop.is_set():
- data = p.poll()
- for (fd, event) in data:
- if fd == stdout.channel.fileno():
- if event == POLLIN:
- line = stdout.readline()
- json_data = json.loads(line)
- self._gerrit.put_event(json_data)
+ try:
+ client = GerritSSHClient(self._host)
+ _stdin, stdout, _stderr = client.run_gerrit_command("stream-events")
+ p = poll()
+ p.register(stdout.channel)
+ while not self._stop.is_set():
+ data = p.poll()
+ for (fd, event) in data:
+ if fd == stdout.channel.fileno():
+ if event == POLLIN:
+ line = stdout.readline()
+ json_data = json.loads(line)
+ self._gerrit.put_event(json_data)
+ except GerritError, e:
+ error = json.loads('{"type":"gerrit-stream-error",'
+ '"error":"%s"}' % str(e))
+ self._gerrit.put_event(error)