From 77f01db969441f37f05996dd2e3b317a54f95572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 30 Mar 2020 17:15:59 +0200 Subject: [PATCH] solve circular dependency --- app.py | 7 ++++--- communicator.py | 2 +- consumerlocator.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 81c318b..b808775 100644 --- a/app.py +++ b/app.py @@ -25,12 +25,13 @@ if __name__ == "__main__": LOGGER.info("Producer started") generateduuid = str(uuid) LOGGER.debug(f"My uuid is {generateduuid}") - consumerlocator = ConsumerLocator(communicator=Communicator()) - communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid) + consumerlocator = ConsumerLocator(uuid=generateduuid) + communicator = Communicator(consumerlocator=consumerlocator,uuid=generateduuid) messagesender = MessageSender(communicator=communicator) while True: - + LOGGER.info(f"Updating consumer list of {generateduuid}") + consumerlocator.updateconsumer() LOGGER.info("Sending message to consumer") messagesender.sendmessage() time.sleep(random.random()) diff --git a/communicator.py b/communicator.py index 675642b..69a7511 100644 --- a/communicator.py +++ b/communicator.py @@ -21,7 +21,7 @@ class Communicator: Class handling low level communication with consumers. """ - def __init__(self, consumerlocator: ConsumerLocator, uuid): + def __init__(self, consumerlocator: ConsumerLocator, uuid: str): """ Initialize object :param consumerlocator: diff --git a/consumerlocator.py b/consumerlocator.py index 82faeda..0a9c55f 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -20,13 +20,13 @@ class ConsumerLocator: Manages the list of consumers. """ - def __init__(self, communicator: Communicator): + def __init__(self, uuid: str): """ Initialize class. """ self.consumerlist = [{"Host": os.environ["KnownConsumer"], "State": True, "LastOk": datetime.datetime.now()}] self.currentconsumer = self.consumerlist[0] - self.communicator = communicator + self.communicator = Communicator(consumerlocator=self,uuid=uuid) def learnconsumerlist(self) -> None: """"