merge PR #1 Communicator API impementation branch: dev-communicator
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-29 20:04:53 +02:00
4 changed files with 70 additions and 85 deletions

46
app.py
View File

@@ -1,12 +1,15 @@
#!/usr/bin/env python
import random
import uuid
import logging
import sentry_sdk
import communicator
import consumerlocator
import messagesender
import time
from communicator import Communicator
from consumerlocator import ConsumerLocator
from messagesender import MessageSender
"""
Main Flask RESTful API
Main entrypoint
"""
__author__ = "@tormakris"
@@ -15,29 +18,18 @@ __module_name__ = "app"
__version__text__ = "1"
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)
if __name__ == "__main__":
print("Producer: init")
comm = communicator.Communicator()
conslist = consumerlocator.ConsumerLocator()
conslist.initcommunicator(comm)
message = messagesender.MessageSender()
LOGGER.info("Producer started")
generateduuid = str(uuid)
LOGGER.debug(f"My uuid is {generateduuid}")
consumerlocator = ConsumerLocator()
communicator = Communicator(consumerlocator=consumerlocator,uuid=uuid)
messagesender = MessageSender(communicator=communicator)
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")
while True:
LOGGER.info("Sending message to consumer")
messagesender.sendmessage()
time.sleep(random.random())