Merge remote-tracking branch 'origin/master'
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
3f6385fe94
@ -19,18 +19,19 @@ class ConsumerLocator:
|
|||||||
Manages the list of consumers.
|
Manages the list of consumers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, comm: communicator.Communicator):
|
||||||
"""
|
"""
|
||||||
Initialize class.
|
Initialize class.
|
||||||
"""
|
"""
|
||||||
self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}]
|
self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}]
|
||||||
self.currentConsumer = self.consumerList[0]["Host"]
|
self.currentConsumer = self.consumerList[0]["Host"]
|
||||||
|
self.communicator = comm
|
||||||
|
|
||||||
def learnconsumerlist(self):
|
def learnconsumerlist(self):
|
||||||
""""
|
""""
|
||||||
Learns the list of consumers.
|
Learns the list of consumers.
|
||||||
"""
|
"""
|
||||||
recievedConsumerList = communicator.discoveravailableconsumers()
|
recievedConsumerList = self.communicator.discoveravailableconsumers()
|
||||||
for consumer in recievedConsumerList:
|
for consumer in recievedConsumerList:
|
||||||
self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})
|
self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})
|
||||||
self.updateConsumerList()
|
self.updateConsumerList()
|
||||||
@ -41,7 +42,7 @@ class ConsumerLocator:
|
|||||||
"""
|
"""
|
||||||
removeList = []
|
removeList = []
|
||||||
for consumer in self.consumerList:
|
for consumer in self.consumerList:
|
||||||
if not communicator.checkconsumer(consumer["Host"]):
|
if not self.communicator.checkconsumer(consumer["Host"]):
|
||||||
consumer["State"] = False
|
consumer["State"] = False
|
||||||
if datetime.datetime.now() - consumer["LastOk"] > datetime.timedelta(hours=1):
|
if datetime.datetime.now() - consumer["LastOk"] > datetime.timedelta(hours=1):
|
||||||
removeList.append(consumer)
|
removeList.append(consumer)
|
||||||
@ -85,7 +86,7 @@ class ConsumerLocator:
|
|||||||
Check the consumers health.
|
Check the consumers health.
|
||||||
:return: True if OK, False if fail
|
:return: True if OK, False if fail
|
||||||
"""
|
"""
|
||||||
if communicator.checkconsumer(self.currentConsumer["Host"]):
|
if self.communicator.checkconsumer(self.currentConsumer["Host"]):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
Reference in New Issue
Block a user