Refactor reset in StatefulEventHandler

This commit is contained in:
Bálint Bokros 2017-12-05 18:35:22 +01:00
parent 6f16a335db
commit ad89c8fb57

View File

@ -16,10 +16,7 @@ class StatefulEventHandler(EventHandlerBase):
def event_handler_callback(msg_parts):
anchor, message = msg_parts
if anchor == b'reset':
self.generator = None
self.unsubscribe_all()
self.subscribe(self.anchor)
self.subscribe('reset')
self.reset()
return
data_json = json.loads(message)
if self.generator is None:
@ -36,3 +33,12 @@ class StatefulEventHandler(EventHandlerBase):
self.zmq_push_socket.send_multipart(response)
self.zmq_sub_stream.on_recv(event_handler_callback)
def unsubscribe_all(self):
super().unsubscribe_all()
self.subscribe('reset')
def reset(self):
self.generator = None
self.unsubscribe_all()
self.subscribe(self.anchor)