mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-05-24 01:12:54 -04:00
fix: remove deprecated lifecycle and consolidate startup actions (#3311)
* remove deprecated lifecycle and consolidate startup actions * fix import
This commit is contained in:
parent
d960947258
commit
1af0f426ae
10
.vscode/tasks.json
vendored
10
.vscode/tasks.json
vendored
@ -24,16 +24,6 @@
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Init Database",
|
||||
"command": "poetry run python mealie/db/init_db.py",
|
||||
"type": "shell",
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"group": "groupA"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Dev: Start Frontend",
|
||||
"command": "task ui",
|
||||
|
@ -132,7 +132,6 @@ tasks:
|
||||
py:
|
||||
desc: runs the backend server
|
||||
cmds:
|
||||
- poetry run python mealie/db/init_db.py
|
||||
- poetry run python mealie/app.py
|
||||
|
||||
py:postgres:
|
||||
@ -145,7 +144,6 @@ tasks:
|
||||
POSTGRES_PORT: 5432
|
||||
POSTGRES_DB: mealie
|
||||
cmds:
|
||||
- poetry run python mealie/db/init_db.py
|
||||
- poetry run python mealie/app.py
|
||||
|
||||
ui:build:
|
||||
|
@ -33,9 +33,6 @@ init() {
|
||||
|
||||
# Activate our virtual environment here
|
||||
. /opt/pysetup/.venv/bin/activate
|
||||
|
||||
# Initialize Database Prerun
|
||||
poetry run python /app/mealie/db/init_db.py
|
||||
}
|
||||
|
||||
change_user
|
||||
|
@ -1,3 +1,6 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@ -39,12 +42,55 @@ community members. If you'd like to file an issue, please use the
|
||||
- [Beta](https://demo.mealie.io)
|
||||
"""
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan_fn(_: FastAPI) -> AsyncGenerator[None, None]:
|
||||
"""
|
||||
lifespan_fn controls the startup and shutdown of the FastAPI Application.
|
||||
This function is called when the FastAPI application starts and stops.
|
||||
|
||||
See FastAPI documentation for more information:
|
||||
- https://fastapi.tiangolo.com/advanced/events/
|
||||
"""
|
||||
logger.info("start: database initialization")
|
||||
import mealie.db.init_db as init_db
|
||||
|
||||
init_db.main()
|
||||
logger.info("end: database initialization")
|
||||
|
||||
await start_scheduler()
|
||||
|
||||
logger.info("-----SYSTEM STARTUP-----")
|
||||
logger.info("------APP SETTINGS------")
|
||||
logger.info(
|
||||
settings.model_dump_json(
|
||||
indent=4,
|
||||
exclude={
|
||||
"SECRET",
|
||||
"SFTP_PASSWORD",
|
||||
"SFTP_USERNAME",
|
||||
"DB_URL", # replace by DB_URL_PUBLIC for logs
|
||||
"DB_PROVIDER",
|
||||
"SMTP_USER",
|
||||
"SMTP_PASSWORD",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
yield
|
||||
|
||||
logger.info("-----SYSTEM SHUTDOWN----- \n")
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Mealie",
|
||||
description=description,
|
||||
version=APP_VERSION,
|
||||
docs_url=settings.DOCS_URL,
|
||||
redoc_url=settings.REDOC_URL,
|
||||
lifespan=lifespan_fn,
|
||||
)
|
||||
|
||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||
@ -103,30 +149,6 @@ for route in app.routes:
|
||||
route.tags = list(set(route.tags))
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def system_startup():
|
||||
logger = get_logger()
|
||||
|
||||
await start_scheduler()
|
||||
|
||||
logger.info("-----SYSTEM STARTUP----- \n")
|
||||
logger.info("------APP SETTINGS------")
|
||||
logger.info(
|
||||
settings.model_dump_json(
|
||||
indent=4,
|
||||
exclude={
|
||||
"SECRET",
|
||||
"SFTP_PASSWORD",
|
||||
"SFTP_USERNAME",
|
||||
"DB_URL", # replace by DB_URL_PUBLIC for logs
|
||||
"DB_PROVIDER",
|
||||
"SMTP_USER",
|
||||
"SMTP_PASSWORD",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
uvicorn.run(
|
||||
"app:app",
|
||||
|
@ -22,7 +22,7 @@ from mealie.services.group_services.group_service import GroupService
|
||||
|
||||
PROJECT_DIR = Path(__file__).parent.parent.parent
|
||||
|
||||
logger = root_logger.get_logger("init_db")
|
||||
logger = root_logger.get_logger()
|
||||
|
||||
|
||||
def init_db(db: AllRepositories) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user