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": []
|
"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",
|
"label": "Dev: Start Frontend",
|
||||||
"command": "task ui",
|
"command": "task ui",
|
||||||
|
@ -132,7 +132,6 @@ tasks:
|
|||||||
py:
|
py:
|
||||||
desc: runs the backend server
|
desc: runs the backend server
|
||||||
cmds:
|
cmds:
|
||||||
- poetry run python mealie/db/init_db.py
|
|
||||||
- poetry run python mealie/app.py
|
- poetry run python mealie/app.py
|
||||||
|
|
||||||
py:postgres:
|
py:postgres:
|
||||||
@ -145,7 +144,6 @@ tasks:
|
|||||||
POSTGRES_PORT: 5432
|
POSTGRES_PORT: 5432
|
||||||
POSTGRES_DB: mealie
|
POSTGRES_DB: mealie
|
||||||
cmds:
|
cmds:
|
||||||
- poetry run python mealie/db/init_db.py
|
|
||||||
- poetry run python mealie/app.py
|
- poetry run python mealie/app.py
|
||||||
|
|
||||||
ui:build:
|
ui:build:
|
||||||
|
@ -33,9 +33,6 @@ init() {
|
|||||||
|
|
||||||
# Activate our virtual environment here
|
# Activate our virtual environment here
|
||||||
. /opt/pysetup/.venv/bin/activate
|
. /opt/pysetup/.venv/bin/activate
|
||||||
|
|
||||||
# Initialize Database Prerun
|
|
||||||
poetry run python /app/mealie/db/init_db.py
|
|
||||||
}
|
}
|
||||||
|
|
||||||
change_user
|
change_user
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
from collections.abc import AsyncGenerator
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
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)
|
- [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(
|
app = FastAPI(
|
||||||
title="Mealie",
|
title="Mealie",
|
||||||
description=description,
|
description=description,
|
||||||
version=APP_VERSION,
|
version=APP_VERSION,
|
||||||
docs_url=settings.DOCS_URL,
|
docs_url=settings.DOCS_URL,
|
||||||
redoc_url=settings.REDOC_URL,
|
redoc_url=settings.REDOC_URL,
|
||||||
|
lifespan=lifespan_fn,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
@ -103,30 +149,6 @@ for route in app.routes:
|
|||||||
route.tags = list(set(route.tags))
|
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():
|
def main():
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"app:app",
|
"app:app",
|
||||||
|
@ -22,7 +22,7 @@ from mealie.services.group_services.group_service import GroupService
|
|||||||
|
|
||||||
PROJECT_DIR = Path(__file__).parent.parent.parent
|
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:
|
def init_db(db: AllRepositories) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user