Add is_running property to the subscriber api in pubsub

This is to allow checking if the subscriber is already running and not
call initialize in that case.

Change-Id: I93583bbd38886032cdd30c6e93651d9e06f24624
This commit is contained in:
Shachar Snapiri 2018-04-30 17:10:10 +03:00
parent c051a44b88
commit 5088f27792
2 changed files with 14 additions and 2 deletions

View File

@ -191,6 +191,11 @@ class SubscriberApi(object):
"""Start the Subscriber thread
"""
@property
@abc.abstractmethod
def is_running(self):
"""Returns True if the subscriber is running, False otherwise"""
@abc.abstractmethod
def close(self):
"""Close the subscriber. Release all used resources"""
@ -217,6 +222,8 @@ class SubscriberAgentBase(SubscriberApi):
def __init__(self):
super(SubscriberAgentBase, self).__init__()
self.db_changes_callback = None
self.daemon = None
self.topic_list = []
self.uri_list = []
@ -238,8 +245,8 @@ class SubscriberAgentBase(SubscriberApi):
self.daemon.start()
@property
def is_daemonize(self):
return self.daemon.is_alive()
def is_running(self):
return self.daemon and self.daemon.is_alive()
def register_topic(self, topic):
LOG.info('Register topic %s', topic)

View File

@ -110,6 +110,11 @@ class EtcdSubscriberAgent(pub_sub_api.SubscriberApi):
for topic in self.topic_dict:
self.topic_dict[topic].start()
@property
def is_running(self):
"""Returns True if the subscriber is running, False otherwise"""
return self.running
def close(self):
self.running = False
for topic, thread in self.topic_dict.items():