Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✨Update✨] How to use with Latest FastAPI version #15

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,42 @@

---

## [✨Update✨] How to use with Latest FastAPI version
With the latest FastAPI version, `on_event` lifespan functions are depreceated. Here is the official [doc](https://fastapi.tiangolo.com/advanced/events/#async-context-manager).
We need to make use of `asynccontextmanager` with the latest fastapi.

Here is an example how to use lifespan (Repeated Tasks) functions with latest fastapi:

```
from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_utilities.repeat import repeat_every, repeat_at

@asynccontextmanager
async def lifespan(app: FastAPI):
# --- startup ---
await test()
test2()
yield
# --- shutdown ---

app = FastAPI(lifespan=lifespan)

# Repeat Every Example
@repeat_every(seconds=2)
async def test():
print("test")

# Repeat At Example
@repeat_at(cron="* * * * *")
def test2():
print("test2")
```

Only difference is to call our tasks from lifespan function instead of using `on_event` function.

---

## [🔥New🔥] FastAPI CLI Tool

With our CLI Tool you can get a skeleton project built to get you started with the code.
Expand Down
Loading