Initial simple implementation of app.py
This commit is contained in:
parent
eaef45cc7d
commit
39113d4b0d
21
app.py
21
app.py
@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
import communicator
|
||||||
|
import consumerlocator
|
||||||
|
import messagesender
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Main Flask RESTful API
|
Main Flask RESTful API
|
||||||
@ -13,4 +17,19 @@ __version__text__ = "1"
|
|||||||
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
|
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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")
|
@ -19,18 +19,21 @@ class ConsumerLocator:
|
|||||||
Manages the list of consumers.
|
Manages the list of consumers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, comm: communicator.Communicator):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialize class.
|
Initialize class.
|
||||||
"""
|
"""
|
||||||
self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}]
|
self.consumerList = [{"Host": "KnownHost", "State": True, "LastOk": datetime.datetime.now()}]
|
||||||
self.currentConsumer = self.consumerList[0]["Host"]
|
self.currentConsumer = self.consumerList[0]["Host"]
|
||||||
|
|
||||||
|
def initCommunicator(self, comm: communicator.Communicator):
|
||||||
self.communicator = comm
|
self.communicator = comm
|
||||||
|
|
||||||
def learnconsumerlist(self):
|
def learnconsumerlist(self):
|
||||||
""""
|
""""
|
||||||
Learns the list of consumers.
|
Learns the list of consumers.
|
||||||
"""
|
"""
|
||||||
|
#TODO improve learning
|
||||||
recievedConsumerList = self.communicator.discoveravailableconsumers()
|
recievedConsumerList = self.communicator.discoveravailableconsumers()
|
||||||
for consumer in recievedConsumerList:
|
for consumer in recievedConsumerList:
|
||||||
self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})
|
self.consumerList.append({"Host": consumer, "State": True, "LastOk": datetime.datetime.now()})
|
||||||
|
Reference in New Issue
Block a user