mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-23 18:49:47 -05:00
Fix: Python docs examples (#2255)
* feat: client example * fix: batch i * fix: batch ii * fix: batch iii * fix: batch iv
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
# > 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)}
|
||||
|
||||
|
||||
# !!
|
||||
Reference in New Issue
Block a user