(app: FastAPI)
| 29 | |
| 30 | @asynccontextmanager |
| 31 | async def lifespan(app: FastAPI): |
| 32 | from app.database import close_database, init_database |
| 33 | from app.services.auth.admin import create_default_admin_if_needed |
| 34 | from app.config import CONFIG |
| 35 | |
| 36 | try: |
| 37 | logger.info("fastapi app startup...") |
| 38 | |
| 39 | logger.info("start plugin cache scheduler...") |
| 40 | _scheduler.add_job(sync_data, "interval", minutes=1) |
| 41 | _scheduler.start() |
| 42 | # first sync |
| 43 | await sync_data(first_sync=True) |
| 44 | |
| 45 | await init_database() |
| 46 | if CONFIG.WEB: |
| 47 | await create_default_admin_if_needed() |
| 48 | |
| 49 | yield |
| 50 | |
| 51 | finally: |
| 52 | logger.info("fastapi app shutdown...") |
| 53 | await close_database() |
| 54 | |
| 55 | |
| 56 | def create_app(): |
nothing calls this directly
no test coverage detected