import logging

from dotenv import load_dotenv

from loralogger.config.settings import ConfigBuilder

# Load the environment variables
load_dotenv()

# Configuration
config = ConfigBuilder.from_env()

# Initialize the worker
try:
    from Connector import Worker

    worker = Worker.create(
        node_name="logger-producer",
        app_name="logger producer",
        worker_queue_name="logger",
        broker_url=config.broker.url,
        result_backend=config.result_backend.url,
    )

    if config.result_backend.sentinel_mode:
        worker.conf.result_backend_transport_options = {"master_name": "redismaster"}

except Exception:
    logging.exception("Cannot initialize producer")
