Files
hatchet/examples/python/fastapi_blog/worker.py
matt 4a50e454a6 Fix: Python docs examples (#2255)
* feat: client example

* fix: batch i

* fix: batch ii

* fix: batch iii

* fix: batch iv
2025-09-05 15:08:23 -04:00

30 lines
671 B
Python

# > Worker
import asyncio
from aiohttp import ClientSession
from hatchet_sdk import Context, EmptyModel, Hatchet
hatchet = Hatchet()
async def fetch(session: ClientSession, url: str) -> bool:
async with session.get(url) as response:
return response.status == 200
@hatchet.task(name="Fetch")
async def hello_from_hatchet(input: EmptyModel, ctx: Context) -> dict[str, int]:
num_requests = 10
async with ClientSession() as session:
tasks = [
fetch(session, "https://docs.hatchet.run/home") for _ in range(num_requests)
]
results = await asyncio.gather(*tasks)
return {"count": results.count(True)}