Switched to external notification module

This commit is contained in:
florian committed 2026-10-17 12:12:28 +02:00
1 parent c5370642c5
commit 162f73fe3f
3 files changed
+15 -79

No files matched your search

+10 -7
View File
@@ -14,9 +14,8 @@ from db_module import (
)
from metrics_server import REQUEST_COUNTER, metrics_api
from secret_manager import cleanup_secret_files
from send_notification import send_notification
from send_notifications import NotificationClient
from simple_logger_handler import LOG_LEVEL, setup_logger
from uvicorn_logger_config import LOGGING_CONFIG
logger = setup_logger(__name__)
@@ -24,7 +23,7 @@ logger = setup_logger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("[App] Starting application...")
app.state.notifier = NotificationClient()
logger.info("[DB] Creating MySQL connection pool...")
create_connection_pool("royalRoadPool")
@@ -81,7 +80,7 @@ def check_for_update(seadex: SeaDexEntry, anilist_id: int) -> str | None:
@api.post("/update")
def check_seadex(db=Depends(get_db)):
def check_seadex(request:Request, db=Depends(get_db)):
results = {"checked": 0, "new": 0, "errors": 0}
with db.cursor() as cursor:
@@ -105,7 +104,11 @@ def check_seadex(db=Depends(get_db)):
logger.info(
f"[FastAPI] {anime_name} updated, Anilist ID: {anilist_id}"
)
send_notification(anime_name, f"https://seadex.moe/{anilist_id}/")
request.app.state.notifier.send(
title=anime_name,
body="SeaDex entry updated",
link=f"https://seadex.moe/{anilist_id}/",
)
with db.cursor() as cursor:
cursor.execute(
@@ -134,8 +137,8 @@ def check_seadex(db=Depends(get_db)):
async def start_servers():
logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...")
config_main = uvicorn.Config(api, host="0.0.0.0", port=5000, log_level=LOG_LEVEL.lower(), log_config=LOGGING_CONFIG)
config_metrics = uvicorn.Config(metrics_api, host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(), log_config=LOGGING_CONFIG)
config_main = uvicorn.Config(api, host="0.0.0.0", port=5000, log_level=LOG_LEVEL.lower(),log_config=None)
config_metrics = uvicorn.Config(metrics_api, host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(),log_config=None)
server_main = uvicorn.Server(config_main)
server_metrics = uvicorn.Server(config_metrics)