Created
May 8, 2023 14:52
-
-
Save topicus/3ee91458917e5f6bf0136a5f489f6916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from fastapi import FastAPI | |
app = FastAPI() | |
async def some_long_running_task(param): | |
await asyncio.sleep(10) # Simulating a long-running task | |
print(f"Task completed with param: {param}") | |
@app.get("/fire-and-forget/{param}") | |
async def fire_and_forget(param: str): | |
asyncio.create_task(some_long_running_task(param)) | |
return {"message": "Task has been started."} | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="127.0.0.1", port=8010) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment