solve circular dependency
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Torma Kristóf 2020-03-30 17:15:59 +02:00
parent 94edf03cf8
commit 77f01db969
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 7 additions and 6 deletions

7
app.py
View File

@ -25,12 +25,13 @@ if __name__ == "__main__":
LOGGER.info("Producer started") LOGGER.info("Producer started")
generateduuid = str(uuid) generateduuid = str(uuid)
LOGGER.debug(f"My uuid is {generateduuid}") LOGGER.debug(f"My uuid is {generateduuid}")
consumerlocator = ConsumerLocator(communicator=Communicator()) consumerlocator = ConsumerLocator(uuid=generateduuid)
communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid) communicator = Communicator(consumerlocator=consumerlocator,uuid=generateduuid)
messagesender = MessageSender(communicator=communicator) messagesender = MessageSender(communicator=communicator)
while True: while True:
LOGGER.info(f"Updating consumer list of {generateduuid}")
consumerlocator.updateconsumer()
LOGGER.info("Sending message to consumer") LOGGER.info("Sending message to consumer")
messagesender.sendmessage() messagesender.sendmessage()
time.sleep(random.random()) time.sleep(random.random())

View File

@ -21,7 +21,7 @@ class Communicator:
Class handling low level communication with consumers. Class handling low level communication with consumers.
""" """
def __init__(self, consumerlocator: ConsumerLocator, uuid): def __init__(self, consumerlocator: ConsumerLocator, uuid: str):
""" """
Initialize object Initialize object
:param consumerlocator: :param consumerlocator:

View File

@ -20,13 +20,13 @@ class ConsumerLocator:
Manages the list of consumers. Manages the list of consumers.
""" """
def __init__(self, communicator: Communicator): def __init__(self, uuid: str):
""" """
Initialize class. Initialize class.
""" """
self.consumerlist = [{"Host": os.environ["KnownConsumer"], "State": True, "LastOk": datetime.datetime.now()}] self.consumerlist = [{"Host": os.environ["KnownConsumer"], "State": True, "LastOk": datetime.datetime.now()}]
self.currentconsumer = self.consumerlist[0] self.currentconsumer = self.consumerlist[0]
self.communicator = communicator self.communicator = Communicator(consumerlocator=self,uuid=uuid)
def learnconsumerlist(self) -> None: def learnconsumerlist(self) -> None:
"""" """"