Added/update docstring
This commit is contained in:
@@ -18,20 +18,25 @@ KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER",'10.69.42.1')
|
||||
class ConsumerLocator:
|
||||
|
||||
"""
|
||||
Manages the list of consumers.
|
||||
Component responsible for managing the list of consumers. Requires an instance of :class:'communicator.Communicator'
|
||||
"""
|
||||
|
||||
def __init__(self, uuid: str, communicator: Communicator):
|
||||
"""
|
||||
Initialize class.
|
||||
"""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.consumerlist = [{"Host": KNOWNCONSUMER, "State": True, "LastOk": datetime.datetime.now()}]
|
||||
self.currentconsumer = self.consumerlist[0]
|
||||
self.communicator = communicator
|
||||
|
||||
def learnconsumerlist(self) -> None:
|
||||
""""
|
||||
Learns the list of consumers.
|
||||
""""Learns the list of consumers from the current consumer.
|
||||
Calls :func:'~communicator.Communicator.didiscoveravailableconsumers', adds the learned consumers to the list
|
||||
if are not present, and then calls :func:'~consumerlocator.ConsumerLocator.updateconsumerlist'
|
||||
:return: None
|
||||
"""
|
||||
recievedconsumerlist = self.communicator.discoveravailableconsumers()
|
||||
if recievedconsumerlist is None:
|
||||
@@ -48,8 +53,10 @@ class ConsumerLocator:
|
||||
self.updateconsumerlist()
|
||||
|
||||
def updateconsumerlist(self) -> None:
|
||||
"""
|
||||
Updates the consumer list based on their availability.
|
||||
""" Updates the consumer list based on their availability.
|
||||
Marks for each consumer if they are available or not. If a consumer is not available for some time (1 hour),
|
||||
the it will be deleted from the list.
|
||||
:return: None
|
||||
"""
|
||||
removelist = []
|
||||
for consumer in self.consumerlist:
|
||||
@@ -64,8 +71,10 @@ class ConsumerLocator:
|
||||
self.consumerlist.remove(rem)
|
||||
|
||||
def updateconsumer(self):
|
||||
"""
|
||||
If the current consumer is not available, checks all the consumers in the list and updates the current one.
|
||||
"""If the current consumer is not available, checks all the consumers in the list and updates the current one.
|
||||
Calls :func:'~consumerlocator.ConsumerLocator.checkcurrentconsumer' and if needed
|
||||
:func:'~consumerlocator.ConsumerLocator.updateconsumerlist'. Sets the :class:'communicator.Communicator'
|
||||
current instance with :func:'~communicator.Communicator.set_currentconsumer'.
|
||||
:return: the current consumer or None if there are no available customers at the moment.
|
||||
"""
|
||||
|
||||
@@ -90,14 +99,14 @@ class ConsumerLocator:
|
||||
|
||||
def getcurrentconsumer(self) -> str:
|
||||
"""
|
||||
Returns the currently selected consumer.
|
||||
Returns the currently selected consumer's IP address.
|
||||
:return: the current consumer
|
||||
"""
|
||||
return self.currentconsumer["Host"]
|
||||
|
||||
def checkcurrentconsumer(self) -> bool:
|
||||
"""
|
||||
Check the consumers health.
|
||||
Check the current consumer's health.
|
||||
:return: True if OK, False if fail
|
||||
"""
|
||||
if self.currentconsumer is None:
|
||||
|
||||
Reference in New Issue
Block a user