feat(py-sdk): async steps (#246)

* feat: async wrapper

* feat: async examples

* release: bump version 0.15.1
This commit is contained in:
Gabe Ruttner
2024-03-06 15:24:44 -08:00
committed by GitHub
parent e8ef805612
commit b9f3ff1609
4 changed files with 64 additions and 7 deletions

View File

@@ -0,0 +1,13 @@
from hatchet_sdk import new_client
from dotenv import load_dotenv
load_dotenv()
client = new_client()
client.event.push(
"user:create",
{
"test": "test"
}
)

View File

@@ -0,0 +1,36 @@
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()