2020-03-29 12:44:20 +02:00
|
|
|
#!/usr/bin/env python
|
2020-03-30 19:33:09 +02:00
|
|
|
|
2020-04-08 18:17:39 +02:00
|
|
|
"""
|
|
|
|
Main entry point, This module builds the producer from the submodules.
|
|
|
|
"""
|
|
|
|
|
2020-03-30 19:33:09 +02:00
|
|
|
import os
|
2020-03-29 20:00:27 +02:00
|
|
|
import random
|
|
|
|
import uuid
|
|
|
|
import logging
|
2020-03-29 12:44:20 +02:00
|
|
|
import sentry_sdk
|
2020-03-29 19:18:25 +02:00
|
|
|
import time
|
2020-03-29 20:00:27 +02:00
|
|
|
from communicator import Communicator
|
|
|
|
from consumerlocator import ConsumerLocator
|
|
|
|
from messagesender import MessageSender
|
2020-04-17 16:47:27 +02:00
|
|
|
from redisconnector import RedisConnector
|
2020-03-29 12:44:20 +02:00
|
|
|
|
|
|
|
__author__ = "@tormakris"
|
|
|
|
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
|
|
|
__module_name__ = "app"
|
|
|
|
__version__text__ = "1"
|
|
|
|
|
|
|
|
sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9")
|
2020-04-01 01:58:49 +02:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG,
|
|
|
|
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
|
|
|
|
datefmt='%Y-%m-%d %H:%M:%S',
|
|
|
|
)
|
2020-03-29 20:00:27 +02:00
|
|
|
LOGGER = logging.getLogger(__name__)
|
2020-03-29 12:44:20 +02:00
|
|
|
|
2020-04-17 16:18:54 +02:00
|
|
|
KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER", '10.69.42.1')
|
2020-03-30 19:52:52 +02:00
|
|
|
|
2020-03-29 12:44:20 +02:00
|
|
|
if __name__ == "__main__":
|
2020-04-08 18:17:39 +02:00
|
|
|
"""
|
|
|
|
This is the producers entry point, initializes all the components (:class:`communicator.Communicator`,
|
|
|
|
:class:`consumerlocator.ConsumerLocator` and :class:`messagesender.MessageSender`) and sends infinite random
|
|
|
|
messages.
|
|
|
|
"""
|
2020-03-29 20:00:27 +02:00
|
|
|
LOGGER.info("Producer started")
|
2020-04-01 01:57:27 +02:00
|
|
|
generateduuid = str(uuid.uuid4())
|
2020-03-30 19:52:52 +02:00
|
|
|
communicator = Communicator(currentconsumer=KNOWNCONSUMER, uuid=generateduuid)
|
2020-03-29 20:00:27 +02:00
|
|
|
LOGGER.debug(f"My uuid is {generateduuid}")
|
2020-04-17 16:47:27 +02:00
|
|
|
consumerlocator = ConsumerLocator(uuid=generateduuid, communicator=communicator,
|
|
|
|
redisconnector=RedisConnector())
|
2020-03-29 20:00:27 +02:00
|
|
|
messagesender = MessageSender(communicator=communicator)
|
2020-03-31 22:58:59 +02:00
|
|
|
consumerlocator.learnconsumerlist()
|
2020-03-29 17:39:31 +02:00
|
|
|
|
2020-03-29 20:00:27 +02:00
|
|
|
while True:
|
2020-03-30 17:15:59 +02:00
|
|
|
LOGGER.info(f"Updating consumer list of {generateduuid}")
|
|
|
|
consumerlocator.updateconsumer()
|
2020-03-29 20:00:27 +02:00
|
|
|
LOGGER.info("Sending message to consumer")
|
|
|
|
messagesender.sendmessage()
|
|
|
|
time.sleep(random.random())
|