Merge remote-tracking branch 'origin/master'
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kovács Bence János 2020-03-29 17:37:26 +02:00
commit 3f6385fe94

View File

@ -19,18 +19,19 @@ class ConsumerLocator:
Manages the list of consumers.
"""
def __init__(self):
def __init__(self, comm: communicator.Communicator):
"""
Initialize class.
"""
self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}]
self.currentConsumer = self.consumerList[0]["Host"]
self.communicator = comm
def learnconsumerlist(self):
""""
Learns the list of consumers.
"""
recievedConsumerList = communicator.discoveravailableconsumers()
recievedConsumerList = self.communicator.discoveravailableconsumers()
for consumer in recievedConsumerList:
self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})
self.updateConsumerList()
@ -41,7 +42,7 @@ class ConsumerLocator:
"""
removeList = []
for consumer in self.consumerList:
if not communicator.checkconsumer(consumer["Host"]):
if not self.communicator.checkconsumer(consumer["Host"]):
consumer["State"] = False
if datetime.datetime.now() - consumer["LastOk"] > datetime.timedelta(hours=1):
removeList.append(consumer)
@ -85,7 +86,7 @@ class ConsumerLocator:
Check the consumers health.
:return: True if OK, False if fail
"""
if communicator.checkconsumer(self.currentConsumer["Host"]):
if self.communicator.checkconsumer(self.currentConsumer["Host"]):
return True
else:
return False