-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlifespan.py
More file actions
37 lines (23 loc) · 721 Bytes
/
lifespan.py
File metadata and controls
37 lines (23 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from contextlib import asynccontextmanager
import pydantic
from fasteda import adapter, app
@asynccontextmanager
async def lifespan():
print("On startup")
try:
yield
finally:
print("On shutdown")
apps = app.FastEDA(adapter=adapter.pydantic, lifespan=lifespan())
class Client(pydantic.BaseModel):
id: int
name: str
@apps.add("client.create.v1")
def create_client(client: Client) -> None:
print(f"{client=} created") # noqa: T201
@apps.add("client.update.v1")
def update_client(client: Client) -> None:
print(f"{client=} updated") # noqa: T201
@apps.add("client.delete.v1")
def delete_client(client: Client) -> None:
print(f"{client=} deleted") # noqa: T201