Merge pull request 'updated the mongo_url to dsqls new url/small type hint fixes' (#16) from development into main
Reviewed-on: #16
This commit was merged in pull request #16.
This commit is contained in:
commit
7f30a8a5cc
4 files changed
+28
-9
No files matched your search
@@ -3,6 +3,8 @@
|
|||||||
import logging
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from motor.motor_asyncio import AsyncIOMotorClient
|
||||||
|
|
||||||
from monitor_utils.constants import LOGGERS
|
from monitor_utils.constants import LOGGERS
|
||||||
from monitor_utils.database import get_collection
|
from monitor_utils.database import get_collection
|
||||||
|
|
||||||
@@ -26,7 +28,11 @@ def is_production(development_mode: DevelopmentMode) -> bool:
|
|||||||
return development_mode == DevelopmentMode.PRODUCTION
|
return development_mode == DevelopmentMode.PRODUCTION
|
||||||
|
|
||||||
|
|
||||||
async def get_config(monitor_name: str, use_production: bool = False) -> dict:
|
async def get_config(
|
||||||
|
monitor_name: str,
|
||||||
|
use_production: bool = False,
|
||||||
|
mongo_client: AsyncIOMotorClient = None,
|
||||||
|
) -> dict:
|
||||||
"""Load a monitor's config document from Mongo.
|
"""Load a monitor's config document from Mongo.
|
||||||
|
|
||||||
Reads the configs collection in production and configs_testing in
|
Reads the configs collection in production and configs_testing in
|
||||||
@@ -36,6 +42,8 @@ async def get_config(monitor_name: str, use_production: bool = False) -> dict:
|
|||||||
monitor_name: Monitor identifier (the config document _id).
|
monitor_name: Monitor identifier (the config document _id).
|
||||||
use_production: Read the production configs collection instead of
|
use_production: Read the production configs collection instead of
|
||||||
configs_testing.
|
configs_testing.
|
||||||
|
mongo_client: Client to read through; the shared cluster client when
|
||||||
|
None.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The config document, including its categories and channels.
|
The config document, including its categories and channels.
|
||||||
@@ -49,7 +57,9 @@ async def get_config(monitor_name: str, use_production: bool = False) -> dict:
|
|||||||
if use_production
|
if use_production
|
||||||
else f"{CONFIGS_COLLECTION_NAME}_testing"
|
else f"{CONFIGS_COLLECTION_NAME}_testing"
|
||||||
)
|
)
|
||||||
config = await get_collection(collection_name).find_one({"_id": monitor_name})
|
config = await get_collection(collection_name, mongo_client=mongo_client).find_one(
|
||||||
|
{"_id": monitor_name}
|
||||||
|
)
|
||||||
if config is None:
|
if config is None:
|
||||||
raise ConfigNotFoundError(monitor_name)
|
raise ConfigNotFoundError(monitor_name)
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ from curl_cffi.requests.errors import RequestsError
|
|||||||
from pymongo.errors import PyMongoError
|
from pymongo.errors import PyMongoError
|
||||||
|
|
||||||
MONGO_DATABASE_NAME = "tpv_woot"
|
MONGO_DATABASE_NAME = "tpv_woot"
|
||||||
MONGO_URL = (
|
MONGO_URL = "mongodb://tpv:mvVuBhhUiCabeNikmUt71L8VqJQHh7IF@ridley.data.dev.ca.rethinkstudios.io:27017/tpv?authSource=admin"
|
||||||
"mongodb://tpv:n3%23QI07GnbZCbvGJ@zelda.disqualifier.me:27017/?authSource=tpv_woot"
|
|
||||||
)
|
|
||||||
LOGGING_LEVEL = "INFO"
|
LOGGING_LEVEL = "INFO"
|
||||||
LOGGERS = [
|
LOGGERS = [
|
||||||
"discord",
|
"discord",
|
||||||
|
|||||||
@@ -30,13 +30,17 @@ NEW_LISTING_PRIORITY = 6
|
|||||||
|
|
||||||
|
|
||||||
def get_collection(
|
def get_collection(
|
||||||
collection_name: str, mongo_client: AsyncIOMotorClient = None
|
collection_name: str,
|
||||||
|
mongo_client: AsyncIOMotorClient = None,
|
||||||
|
database_name=MONGO_DATABASE_NAME,
|
||||||
) -> AsyncIOMotorCollection:
|
) -> AsyncIOMotorCollection:
|
||||||
|
# rename mongo_client to client and add optional database name arg
|
||||||
"""Return the named collection from the shared client's database.
|
"""Return the named collection from the shared client's database.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
collection_name: Name of the collection to return.
|
collection_name: Name of the collection to return.
|
||||||
mongo_client: optional client for projects with already configured client
|
mongo_client: optional client for projects with already configured client
|
||||||
|
database_name: optional name to use besides the default mongo database name
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The requested collection.
|
The requested collection.
|
||||||
@@ -45,7 +49,7 @@ def get_collection(
|
|||||||
if mongo_client is None:
|
if mongo_client is None:
|
||||||
mongo_client = get_mongo_client()
|
mongo_client = get_mongo_client()
|
||||||
|
|
||||||
return mongo_client[MONGO_DATABASE_NAME][collection_name]
|
return mongo_client[database_name][collection_name]
|
||||||
|
|
||||||
|
|
||||||
def resolve_alerts_collection(
|
def resolve_alerts_collection(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from aioproxies import AioProxies
|
|||||||
from curl_cffi.requests import AsyncSession
|
from curl_cffi.requests import AsyncSession
|
||||||
from log_setup import setup_logging
|
from log_setup import setup_logging
|
||||||
from motor.motor_asyncio import AsyncIOMotorCollection
|
from motor.motor_asyncio import AsyncIOMotorCollection
|
||||||
|
from motor.motor_asyncio import AsyncIOMotorClient
|
||||||
|
|
||||||
from monitor_utils.config import (
|
from monitor_utils.config import (
|
||||||
DevelopmentMode,
|
DevelopmentMode,
|
||||||
@@ -91,7 +92,9 @@ async def init_monitor(
|
|||||||
|
|
||||||
|
|
||||||
async def setup_config(
|
async def setup_config(
|
||||||
monitor_name: str, development_mode: DevelopmentMode
|
monitor_name: str,
|
||||||
|
development_mode: DevelopmentMode,
|
||||||
|
mongo_client: AsyncIOMotorClient = None,
|
||||||
) -> tuple[
|
) -> tuple[
|
||||||
list[str] | dict[str, str], dict[str, str | list[str]], AsyncIOMotorCollection
|
list[str] | dict[str, str], dict[str, str | list[str]], AsyncIOMotorCollection
|
||||||
]:
|
]:
|
||||||
@@ -105,6 +108,8 @@ async def setup_config(
|
|||||||
monitor_name: Monitor identifier used for config and collection lookup.
|
monitor_name: Monitor identifier used for config and collection lookup.
|
||||||
development_mode: Selects the production or testing config and
|
development_mode: Selects the production or testing config and
|
||||||
collection.
|
collection.
|
||||||
|
mongo_client: Client the config read and the returned collection use;
|
||||||
|
the shared cluster client when None.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of category names, channel id mapping, and Mongo collection.
|
Tuple of category names, channel id mapping, and Mongo collection.
|
||||||
@@ -114,11 +119,13 @@ async def setup_config(
|
|||||||
config = await get_config(
|
config = await get_config(
|
||||||
monitor_name=monitor_name,
|
monitor_name=monitor_name,
|
||||||
use_production=use_production,
|
use_production=use_production,
|
||||||
|
mongo_client=mongo_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
category_names = config["categories"]
|
category_names = config["categories"]
|
||||||
collection = get_collection(
|
collection = get_collection(
|
||||||
monitor_name if use_production else f"{monitor_name}_testing"
|
monitor_name if use_production else f"{monitor_name}_testing",
|
||||||
|
mongo_client=mongo_client,
|
||||||
)
|
)
|
||||||
return category_names, config["channels"], collection
|
return category_names, config["channels"], collection
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user