|
| 1 | +from collections.abc import AsyncGenerator |
| 2 | +from contextlib import asynccontextmanager |
| 3 | + |
1 | 4 | from fastapi import FastAPI
|
2 | 5 | from httpx_oauth.clients.google import GoogleOAuth2
|
3 | 6 | from httpx_oauth.clients.openid import BASE_SCOPES
|
|
44 | 47 | from onyx.main import get_application as get_application_base
|
45 | 48 | from onyx.main import include_auth_router_with_prefix
|
46 | 49 | from onyx.main import include_router_with_global_prefix_prepended
|
| 50 | +from onyx.main import lifespan as lifespan_base |
47 | 51 | from onyx.utils.logger import setup_logger
|
48 | 52 | from onyx.utils.variable_functionality import global_version
|
49 | 53 | from shared_configs.configs import MULTI_TENANT
|
50 | 54 |
|
51 | 55 | logger = setup_logger()
|
52 | 56 |
|
53 | 57 |
|
| 58 | +@asynccontextmanager |
| 59 | +async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: |
| 60 | + """Small wrapper around the lifespan of the MIT application. |
| 61 | + Basically just calls the base lifespan, and then adds EE-only |
| 62 | + steps after.""" |
| 63 | + |
| 64 | + async with lifespan_base(app): |
| 65 | + # seed the Onyx environment with LLMs, Assistants, etc. based on an optional |
| 66 | + # environment variable. Used to automate deployment for multiple environments. |
| 67 | + seed_db() |
| 68 | + |
| 69 | + yield |
| 70 | + |
| 71 | + |
54 | 72 | def get_application() -> FastAPI:
|
55 | 73 | # Anything that happens at import time is not guaranteed to be running ee-version
|
56 | 74 | # Anything after the server startup will be running ee version
|
57 | 75 | global_version.set_ee()
|
58 | 76 |
|
59 | 77 | test_encryption()
|
60 | 78 |
|
61 |
| - application = get_application_base() |
| 79 | + application = get_application_base(lifespan_override=lifespan) |
62 | 80 |
|
63 | 81 | if MULTI_TENANT:
|
64 | 82 | add_tenant_id_middleware(application, logger)
|
@@ -166,10 +184,6 @@ def get_application() -> FastAPI:
|
166 | 184 | # Ensure all routes have auth enabled or are explicitly marked as public
|
167 | 185 | check_ee_router_auth(application)
|
168 | 186 |
|
169 |
| - # seed the Onyx environment with LLMs, Assistants, etc. based on an optional |
170 |
| - # environment variable. Used to automate deployment for multiple environments. |
171 |
| - seed_db() |
172 |
| - |
173 | 187 | # for debugging discovered routes
|
174 | 188 | # for route in application.router.routes:
|
175 | 189 | # print(f"Path: {route.path}, Methods: {route.methods}")
|
|
0 commit comments