Files
hatchet/examples/python/lifespans/simple.py
Gabe Ruttner 8e80faf2d6 Fe overhaul docs (#1640)
* api changes

* doc changes

* move docs

* generated

* generate

* pkg

* backmerge main

* revert to main

* revert main

* race?

* remove go tests
2025-04-30 14:10:09 -07:00

36 lines
663 B
Python

# > Lifespan
from typing import AsyncGenerator, cast
from pydantic import BaseModel
from hatchet_sdk import Context, EmptyModel, Hatchet
hatchet = Hatchet(debug=True)
class Lifespan(BaseModel):
foo: str
pi: float
async def lifespan() -> AsyncGenerator[Lifespan, None]:
yield Lifespan(foo="bar", pi=3.14)
@hatchet.task(name="LifespanWorkflow")
def lifespan_task(input: EmptyModel, ctx: Context) -> Lifespan:
return cast(Lifespan, ctx.lifespan)
def main() -> None:
worker = hatchet.worker(
"test-worker", slots=1, workflows=[lifespan_task], lifespan=lifespan
)
worker.start()
if __name__ == "__main__":
main()