Wire all components together #2
3
app.py
3
app.py
@ -25,11 +25,12 @@ 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()
|
consumerlocator = ConsumerLocator(communicator=Communicator())
|
||||||
communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid)
|
communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid)
|
||||||
messagesender = MessageSender(communicator=communicator)
|
messagesender = MessageSender(communicator=communicator)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
LOGGER.info("Sending message to consumer")
|
LOGGER.info("Sending message to consumer")
|
||||||
messagesender.sendmessage()
|
messagesender.sendmessage()
|
||||||
time.sleep(random.random())
|
time.sleep(random.random())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import communicator
|
from communicator import Communicator
|
||||||
import os
|
import os
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -20,22 +20,15 @@ class ConsumerLocator:
|
|||||||
Manages the list of consumers.
|
Manages the list of consumers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, communicator: Communicator):
|
||||||
"""
|
"""
|
||||||
Initialize class.
|
Initialize class.
|
||||||
"""
|
"""
|
||||||
os.environ["KnownConsumer"] = "10.69.42.2" # TODO remove
|
|
||||||
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
|
||||||
|
|
||||||
def initcommunicator(self, comm: communicator.Communicator):
|
def learnconsumerlist(self) -> None:
|
||||||
"""
|
|
||||||
Initialize the reference to the communicator
|
|
||||||
:param comm: is the communicator
|
|
||||||
"""
|
|
||||||
self.communicator = comm
|
|
||||||
|
|
||||||
def learnconsumerlist(self):
|
|
||||||
""""
|
""""
|
||||||
Learns the list of consumers.
|
Learns the list of consumers.
|
||||||
"""
|
"""
|
||||||
@ -53,7 +46,7 @@ class ConsumerLocator:
|
|||||||
|
|
||||||
self.updateconsumerlist()
|
self.updateconsumerlist()
|
||||||
|
|
||||||
def updateconsumerlist(self):
|
def updateconsumerlist(self) -> None:
|
||||||
"""
|
"""
|
||||||
Updates the consumer list based on their availability.
|
Updates the consumer list based on their availability.
|
||||||
"""
|
"""
|
||||||
@ -93,14 +86,14 @@ class ConsumerLocator:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getcurrentconsumer(self):
|
def getcurrentconsumer(self) -> str:
|
||||||
"""
|
"""
|
||||||
Returns the currently selected consumer.
|
Returns the currently selected consumer.
|
||||||
:return: the current consumer
|
:return: the current consumer
|
||||||
"""
|
"""
|
||||||
return self.currentconsumer["Host"]
|
return self.currentconsumer["Host"]
|
||||||
|
|
||||||
def checkcurrentconsumer(self):
|
def checkcurrentconsumer(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Check the consumers health.
|
Check the consumers health.
|
||||||
:return: True if OK, False if fail
|
:return: True if OK, False if fail
|
||||||
|
Reference in New Issue
Block a user