mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-28 19:47:41 +08:00
feat(setup): support asynchronous install plugins on startup
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.startup.module_initializer import start_modules, shutdown_modules
|
||||
from app.startup.routers import init_routers
|
||||
from app.startup.modules_initializer import shutdown_modules, start_modules
|
||||
from app.startup.plugins_initializer import init_plugins_async
|
||||
from app.startup.routers_initializer import init_routers
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -14,6 +16,16 @@ async def lifespan(app: FastAPI):
|
||||
print("Starting up...")
|
||||
start_modules(app)
|
||||
init_routers(app)
|
||||
yield
|
||||
print("Shutting down...")
|
||||
shutdown_modules(app)
|
||||
plugin_init_task = asyncio.create_task(init_plugins_async())
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
print("Shutting down...")
|
||||
try:
|
||||
plugin_init_task.cancel()
|
||||
await plugin_init_task
|
||||
except asyncio.CancelledError:
|
||||
print("Plugin installation task cancelled.")
|
||||
except Exception as e:
|
||||
print(f"Error during plugin installation shutdown: {e}")
|
||||
shutdown_modules(app)
|
||||
|
||||
Reference in New Issue
Block a user