INNER CODE UNIT · Python
lifespan
Quenary/tugtainer · backend/app.py:67
async def lifespan(app: FastAPI):
# Code to run on startup
await load_agents_on_init()
await SettingsStorage.load_all()
await schedule_jobs_on_init()
try:
await cleanup_all_stale_containers()
except Exception:
logging.exception("Failed to run stale containers cleanup on startup")
yield # App
# Code to run on shutdown
await AgentClientManager.remove_all()
app = FastAPI(root_path="/api", lifespan=lifespan)
app.include_router(auth_router)
app.include_router(containers_router)
app.include_router(public_router)