add consumerinformation

This commit is contained in:
2020-05-14 20:09:41 +02:00
parent 20a1aa6dfa
commit 6bdcb40220
6 changed files with 142 additions and 49 deletions

View File

@@ -20,18 +20,16 @@ LOGGER = logging.getLogger(__name__)
class ConsumerLocator:
"""
Component responsible for managing the list of consumers. Requires an instance of :class:`communicator.Communicator`
"""
def __init__(self, uuid: str, communicator: Communicator, redisconnector: RedisConnector):
def __init__(self, communicator: Communicator, redisconnector: RedisConnector):
"""**Constructor:**
Initializes the object.
Gets the known consumer's IP address from the PRODUCER_KNOWNCONSUMER envar.
:param uuid: Not used
:param communicator: the :class:'communicator.Communicator' instance that will be used for the low level communication.
"""
self.red = redisconnector
@@ -51,7 +49,6 @@ class ConsumerLocator:
if not recievedconsumerlist:
return
consumer_list = self.red.consumerlist
for recconsumer in recievedconsumerlist:
@@ -62,7 +59,8 @@ class ConsumerLocator:
if not contains:
LOGGER.info(f"Learned about new consumer at {recconsumer}")
consumer_list.append({"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()})
consumer_list.append(
{"Host": recconsumer, "State": True, "LastOk": datetime.datetime.now().timestamp()})
self.red.consumerlist = consumer_list
self.updateconsumerlist()
@@ -81,7 +79,8 @@ class ConsumerLocator:
for consumer in consumer_list:
if not self.communicator.checkconsumer(consumer["Host"]):
consumer["State"] = False
if datetime.datetime.now() - datetime.datetime.fromtimestamp(consumer["LastOk"]) > datetime.timedelta(hours=1):
if datetime.datetime.now() - datetime.datetime.fromtimestamp(consumer["LastOk"]) > datetime.timedelta(
hours=1):
removelist.append(consumer)
else:
consumer["LastOk"] = datetime.datetime.now().timestamp()