diff --git a/app.py b/app.py index dff38f2..34e9f4e 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,9 @@ #!/usr/bin/env python import sentry_sdk +import communicator +import consumerlocator +import messagesender + """ Main Flask RESTful API @@ -13,4 +17,19 @@ __version__text__ = "1" sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9") if __name__ == "__main__": - print("Producer") \ No newline at end of file + print("Producer: init") + comm = communicator.Communicator() + conslist = consumerlocator.ConsumerLocator() + conslist.initCommunicator(comm) + message = messagesender.MessageSender() + + conslist.learnconsumerlist() + print("Producer: started sending") + for i in range(30): + print("Producer: send %i message", i) + msg = message.CreateMessage(20) + if not conslist.checkcurrentconsumer(): + conslist.updateconsumer() + comm.sendmessage(msg) + + print("Producer: finished") \ No newline at end of file diff --git a/consumerlocator.py b/consumerlocator.py index 31b7944..fdb5d5d 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -19,18 +19,21 @@ class ConsumerLocator: Manages the list of consumers. """ - def __init__(self, comm: communicator.Communicator): + def __init__(self): """ Initialize class. """ self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}] self.currentConsumer = self.consumerList[0]["Host"] + + def initCommunicator(self, comm: communicator.Communicator): self.communicator = comm def learnconsumerlist(self): """" Learns the list of consumers. """ +#TODO improve learning recievedConsumerList = self.communicator.discoveravailableconsumers() for consumer in recievedConsumerList: self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})