Compare commits
No commits in common. "ed01ead04d6d63d54a64c80a4443ca5567e6a3b3" and "62f059b4613030d0104764ce3eb9ea6a47a38e79" have entirely different histories.
ed01ead04d
...
62f059b461
6
app.py
6
app.py
@ -25,13 +25,11 @@ if __name__ == "__main__":
|
||||
LOGGER.info("Producer started")
|
||||
generateduuid = str(uuid)
|
||||
LOGGER.debug(f"My uuid is {generateduuid}")
|
||||
consumerlocator = ConsumerLocator(uuid=generateduuid)
|
||||
communicator = Communicator(consumerlocator=consumerlocator,uuid=generateduuid)
|
||||
consumerlocator = ConsumerLocator()
|
||||
communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid)
|
||||
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())
|
||||
|
@ -21,7 +21,7 @@ class Communicator:
|
||||
Class handling low level communication with consumers.
|
||||
"""
|
||||
|
||||
def __init__(self, consumerlocator: ConsumerLocator, uuid: str):
|
||||
def __init__(self, consumerlocator: ConsumerLocator, uuid):
|
||||
"""
|
||||
Initialize object
|
||||
:param consumerlocator:
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import datetime
|
||||
from communicator import Communicator
|
||||
import communicator
|
||||
import os
|
||||
|
||||
"""
|
||||
@ -20,15 +20,22 @@ class ConsumerLocator:
|
||||
Manages the list of consumers.
|
||||
"""
|
||||
|
||||
def __init__(self, uuid: str):
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize class.
|
||||
"""
|
||||
os.environ["KnownConsumer"] = "10.69.42.2" # TODO remove
|
||||
self.consumerlist = [{"Host": os.environ["KnownConsumer"], "State": True, "LastOk": datetime.datetime.now()}]
|
||||
self.currentconsumer = self.consumerlist[0]
|
||||
self.communicator = Communicator(consumerlocator=self,uuid=uuid)
|
||||
|
||||
def learnconsumerlist(self) -> None:
|
||||
def initcommunicator(self, comm: communicator.Communicator):
|
||||
"""
|
||||
Initialize the reference to the communicator
|
||||
:param comm: is the communicator
|
||||
"""
|
||||
self.communicator = comm
|
||||
|
||||
def learnconsumerlist(self):
|
||||
""""
|
||||
Learns the list of consumers.
|
||||
"""
|
||||
@ -46,7 +53,7 @@ class ConsumerLocator:
|
||||
|
||||
self.updateconsumerlist()
|
||||
|
||||
def updateconsumerlist(self) -> None:
|
||||
def updateconsumerlist(self):
|
||||
"""
|
||||
Updates the consumer list based on their availability.
|
||||
"""
|
||||
@ -86,14 +93,14 @@ class ConsumerLocator:
|
||||
else:
|
||||
return None
|
||||
|
||||
def getcurrentconsumer(self) -> str:
|
||||
def getcurrentconsumer(self):
|
||||
"""
|
||||
Returns the currently selected consumer.
|
||||
:return: the current consumer
|
||||
"""
|
||||
return self.currentconsumer["Host"]
|
||||
|
||||
def checkcurrentconsumer(self) -> bool:
|
||||
def checkcurrentconsumer(self):
|
||||
"""
|
||||
Check the consumers health.
|
||||
:return: True if OK, False if fail
|
||||
|
Reference in New Issue
Block a user