moving config storage to mongo

This commit is contained in:
TPV committed 2026-07-13 10:25:07 -07:00
1 parent 9bc34d4dc9
commit 7d070dec40
2 files changed
+43 -30

No files matched your search

+14 -11
View File
@@ -28,18 +28,20 @@ from monitor_utils.sessions import get_base_session, get_tls_session
LOGGER = logging.getLogger(__name__)
def init_monitor(
async def init_monitor(
monitor_name: str,
development_mode: DevelopmentMode,
production_proxy_path: str = "proxies.txt",
testing_proxy_path: str = "configs/proxies.txt",
logging_level=LOGGING_LEVEL,
) -> tuple[list[str], AsyncIOMotorCollection, AioProxies]:
) -> tuple[list[str] | dict[str, str], AsyncIOMotorCollection, AioProxies]:
"""Run shared monitor startup and return categories, collection, and proxies.
Configures JSON logging under the monitor's name, applies logger levels,
loads the monitor config and Mongo collection, and loads proxies from the
production or testing path based on development_mode.
production or testing path based on development_mode. Async because the
config now lives in Mongo; call it from inside the monitor's event loop
(in main), not at module import.
Args:
monitor_name: Monitor identifier used for logging and config lookup.
@@ -61,7 +63,7 @@ def init_monitor(
output="json",
)
set_logger_levels()
category_names, _, collection = setup_config(
category_names, _, collection = await setup_config(
monitor_name=monitor_name, development_mode=development_mode
)
proxy_path = production_proxy_path if use_production else testing_proxy_path
@@ -69,17 +71,18 @@ def init_monitor(
return category_names, collection, proxies
def setup_config(
async def setup_config(
monitor_name: str, development_mode: DevelopmentMode
) -> tuple[list[str], dict[int], AsyncIOMotorCollection]:
) -> tuple[list[str] | dict[str, str], dict[str, str | list[str]], AsyncIOMotorCollection]:
"""Load monitor config and resolve the Mongo collection for the mode.
Testing mode appends a _testing suffix to the collection name so
production data is never touched during development.
Testing mode reads the configs_testing collection and appends a _testing
suffix to the product collection name so production data is never touched
during development.
Args:
monitor_name: Monitor identifier used for config and collection lookup.
development_mode: Selects the production or testing config path and
development_mode: Selects the production or testing config and
collection.
Returns:
@@ -87,9 +90,9 @@ def setup_config(
"""
use_production = is_production(development_mode)
config, _ = get_config(
config = await get_config(
monitor_name=monitor_name,
use_production_path=use_production,
use_production=use_production,
)
category_names = config["categories"]