Merge branch 'master' of gitea:GoldenPogacsa/producer
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
459806683a
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")
|
@ -4,10 +4,10 @@ import datetime
|
|||||||
import communicator
|
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"
|
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
||||||
__module_name__ = "consumerlocator"
|
__module_name__ = "consumerlocator"
|
||||||
__version__text__ = "1"
|
__version__text__ = "1"
|
||||||
@ -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