diff --git a/monitor_utils/config.py b/monitor_utils/config.py index 0d0aa4c..689c261 100644 --- a/monitor_utils/config.py +++ b/monitor_utils/config.py @@ -2,21 +2,25 @@ import logging import json import pathlib from functools import cache +from typing import Enum from logging.handlers import RotatingFileHandler from monitor_utils.constants import ( PROXIES_PATH, PROJECT_ROOT, - DEVELOPMENT_MODE, PRODUCTION_BOT_TOKEN, DEVELOPMENT_BOT_TOKEN, LOGGING_LEVEL, - DevelopmentMode, ) RESERVED = frozenset(logging.LogRecord("", 0, "", 0, "", (), None).__dict__) +class DevelopmentMode(str, Enum): + PRODUCTION = "PRODUCTION" + DEVELOPMENT = "DEVELOPMENT" + + class JSONFormatter(logging.Formatter): def format(self, record: logging.LogRecord) -> str: payload = { @@ -63,11 +67,8 @@ def configure_logging(monitor_name: str): logging.getLogger("pymongo").setLevel(logging.WARNING) -def is_production(override_production=False) -> bool: - if override_production: - return False - - return DEVELOPMENT_MODE == DevelopmentMode.PRODUCTION +def is_production(development_mode: DevelopmentMode) -> bool: + return development_mode == DevelopmentMode.PRODUCTION def get_bot_token(is_production: bool) -> str: diff --git a/monitor_utils/constants.py b/monitor_utils/constants.py index ba8944b..e831248 100644 --- a/monitor_utils/constants.py +++ b/monitor_utils/constants.py @@ -1,6 +1,5 @@ import asyncio import pathlib -from enum import Enum import aiohttp import requests @@ -23,12 +22,6 @@ PROFIT_API_KEY = "dev-XvIu8S83BJ2N1C9ZCsoLAAav5jan7kj5" LOGGING_LEVEL = "INFO" -class DevelopmentMode(str, Enum): - PRODUCTION = "PRODUCTION" - DEVELOPMENT = "DEVELOPMENT" - - -DEVELOPMENT_MODE = DevelopmentMode.PRODUCTION RETRY_LIMIT = 5 RETRY_WAIT = 3 BACKOFF_DELAY = 0.001 diff --git a/monitor_utils/runner.py b/monitor_utils/runner.py index b148c89..f002545 100644 --- a/monitor_utils/runner.py +++ b/monitor_utils/runner.py @@ -13,7 +13,7 @@ from monitor_utils.constants import ( BUCKET_WEBHOOK_MAP, LOGGING_LEVEL, ) -from monitor_utils.config import get_config, is_production +from monitor_utils.config import get_config, is_production, DevelopmentMode from monitor_utils.models import ( Product, ProductMetadata, @@ -28,9 +28,9 @@ LOGGER = logging.getLogger(__name__) def setup_config( - monitor_name: str, override_production=False + monitor_name: str, development_mode: DevelopmentMode ) -> tuple[list[str], dict, AsyncIOMotorCollection]: - use_production = is_production(override_production) + use_production = is_production(development_mode) config, _ = get_config( monitor_name=monitor_name, use_production_path=use_production,