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
Torma Kristóf 87217d121d
All checks were successful
continuous-integration/drone/push Build is passing
generate uuid
2020-04-01 01:57:27 +02:00

43 lines
1.2 KiB
Python

#!/usr/bin/env python
import os
import random
import uuid
import logging
import sentry_sdk
import time
from communicator import Communicator
from consumerlocator import ConsumerLocator
from messagesender import MessageSender
"""
Main entrypoint
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
__module_name__ = "app"
__version__text__ = "1"
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)
KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER",'10.69.42.1')
if __name__ == "__main__":
LOGGER.info("Producer started")
generateduuid = str(uuid.uuid4())
communicator = Communicator(currentconsumer=KNOWNCONSUMER, uuid=generateduuid)
LOGGER.debug(f"My uuid is {generateduuid}")
consumerlocator = ConsumerLocator(uuid=generateduuid, communicator=communicator)
messagesender = MessageSender(communicator=communicator)
consumerlocator.learnconsumerlist()
while True:
LOGGER.info(f"Updating consumer list of {generateduuid}")
consumerlocator.updateconsumer()
LOGGER.info("Sending message to consumer")
messagesender.sendmessage()
time.sleep(random.random())