Initial simple implementation of app.py

This commit is contained in:
Scharnitzky Donát 2020-03-29 17:39:31 +02:00
parent eaef45cc7d
commit 39113d4b0d
2 changed files with 24 additions and 2 deletions

21
app.py
View File

@ -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")
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")

View File

@ -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()})