-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (38 loc) · 1.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from fastapi import FastAPI
from components.db import init_db
from components.log import init_log, log
from components.env import init_env
from apis.gpts import gpts_router
from apis.ollama import ollama_router
from apis.test import test_router
from apis.audio import audio_router
# 示例化
app = FastAPI()
app.include_router(audio_router)
app.include_router(gpts_router)
app.include_router(ollama_router)
app.include_router(test_router)
@app.on_event("startup")
async def startup():
"""
Startup function to initialize various components of the application.
This function is responsible for initializing the logging system, environment variables,
and the database connection. It ensures that all necessary components are set up
before the application starts.
Note:
- This function is asynchronous and should be awaited when called.
- The order of initialization is important, as subsequent operations may depend on
the successful completion of previous steps.
Returns:
None
"""
print("init log")
init_log()
print("init env")
init_env()
print("init db")
init_db()
log.info("app start")
@app.on_event("shutdown")
async def shutdown():
log.info("app shutdown")