generated from kgod/ai-review-template
提交
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
"""项目主入口"""
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from src.scheduler import start_scheduler, shutdown_scheduler
|
||||
from src.browser import close_browser
|
||||
|
||||
# 配置日志
|
||||
import sys
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(levelname)s: %(message)s",
|
||||
stream=sys.stdout
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""应用生命周期管理"""
|
||||
# 启动时
|
||||
start_scheduler()
|
||||
yield
|
||||
# 关闭时
|
||||
shutdown_scheduler()
|
||||
await close_browser()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Crawler",
|
||||
version="1.0.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
"""健康检查"""
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
Reference in New Issue
Block a user