Files
hatchet/python-sdk/examples/async/worker.py
Gabe Ruttner b9f3ff1609 feat(py-sdk): async steps (#246)
* feat: async wrapper

* feat: async examples

* release: bump version 0.15.1
2024-03-06 15:24:44 -08:00

36 lines
903 B
Python

from hatchet_sdk import Hatchet, Context
from dotenv import load_dotenv
import asyncio
load_dotenv()
hatchet = Hatchet(debug=True)
@hatchet.workflow(on_events=["user:create"])
class AsyncWorkflow:
def __init__(self):
self.my_value = "test"
@hatchet.step(timeout='5s')
def step1(self, context: Context):
async def async_step1():
print("started step1")
await asyncio.sleep(2)
print("finished step1")
return 'result'
res = asyncio.run(async_step1())
print(res)
return {'test': 'test'}
@hatchet.step(parents=["step1"],timeout='4s')
async def step2(self, context):
print("started async step2")
await asyncio.sleep(2)
print("finished step2")
workflow = AsyncWorkflow()
worker = hatchet.worker('test-worker', max_runs=4)
worker.register_workflow(workflow)
worker.start()