Skip to content

Commit c43681d

Browse files
committed
feat: add notify_admin
1 parent e8f8102 commit c43681d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ DATABASE_PORT=3306
44
DATABASE_USER=""
55
DATABASE_PASSWD=""
66

7+
NOTIFY_ADMIN_URL=""
8+
79
STATIC_APP_DIR="/app/static"

src/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Settings(BaseSettings):
1010

1111
static_app_dir: str
1212

13+
notify_admin_url: str
14+
1315
class Config:
1416
env_file = ".env"
1517

src/notify_admin/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from fastapi import Request, APIRouter
2+
from aiohttp import ClientSession
3+
from loguru import logger
4+
5+
from src.config import settings
6+
7+
router = APIRouter()
8+
9+
@router.post("/notify_admin")
10+
async def notify_admin(request: Request):
11+
body = await request.json()
12+
logger.info(str(body))
13+
14+
try:
15+
async with ClientSession() as session:
16+
async with session.post(
17+
settings.notify_admin_url, json=body
18+
) as response:
19+
pass
20+
except Exception as e:
21+
logger.error(f"notify_admin error: {e}, body: f{body}")

0 commit comments

Comments
 (0)