This commit is contained in:
2025-03-08 18:37:22 -07:00
parent da4c5203b3
commit d7b7d5efe1

View File

@@ -111,12 +111,22 @@ async def start_websocket_server():
await asyncio.Future() await asyncio.Future()
@asynccontextmanager @asynccontextmanager
async def lifespan(app: FastAPI): async def lifespan(app: FastAPI):
asyncio.create_task(start_websocket_server()) # Start WebSocket and Discord bot in managed background tasks
asyncio.create_task(bot.start(os.getenv("DISCORD_SECRET"))) websocket_task = asyncio.create_task(start_websocket_server())
bot_task = asyncio.create_task(bot.start(os.getenv("DISCORD_SECRET")))
app.state.websocket_task = websocket_task
app.state.bot_task = bot_task
yield yield
app.state.websocket_task.cancel()
app.state.bot_task.cancel()
await asyncio.gather(app.state.websocket_task, app.state.bot_task, return_exceptions=True)
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
app.mount("/", StaticFiles(directory="./client", html=True), name="static") app.mount("/", StaticFiles(directory="./client", html=True), name="static")