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 f1af3a3..fdb5d5d 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -4,10 +4,10 @@ import datetime import communicator """ -Main Flask RESTful API +Consumer locator modul, that manages the list of consumers. """ -__author__ = "@tormakris" +__author__ = "@dscharnitzky" __copyright__ = "Copyright 2020, GoldenPogácsa Team" __module_name__ = "consumerlocator" __version__text__ = "1" @@ -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()})