This repository has been archived on 2020-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
producer/app.py
schdwlk 2b44a5bbad
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
Added environment variable and fixed stuff
2020-03-29 19:18:25 +02:00

43 lines
1.2 KiB
Python

#!/usr/bin/env python
import sentry_sdk
import communicator
import consumerlocator
import messagesender
import time
"""
Main Flask RESTful API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
__module_name__ = "app"
__version__text__ = "1"
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
if __name__ == "__main__":
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):
msg = message.createMessage(20)
print("Producer: trying to send ", i, "th message: ", msg)
available = False
if conslist.updateconsumer() is None:
print("Producer: no consumer available (waiting a bit)")
time.sleep(1)
else:
available = True
if available:
comm.sendmessage(msg)
print("Producer: message sent")
else:
print("Producer: failed to send message")
print("Producer: finished")