small refactor
This commit is contained in:
1 parent
0b9df71be9
commit
13c54f033c
3 files changed
+11
-17
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user