small refactor

This commit is contained in:
tpv committed 2026-06-24 19:46:56 -07:00
1 parent 0b9df71be9
commit 13c54f033c
3 files changed
+11 -17

No files matched your search

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