mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 23:59:49 -06:00
feat(py-sdk): async steps (#246)
* feat: async wrapper * feat: async examples * release: bump version 0.15.1
This commit is contained in:
13
python-sdk/examples/async/event_test.py
Normal file
13
python-sdk/examples/async/event_test.py
Normal 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"
|
||||
}
|
||||
)
|
||||
36
python-sdk/examples/async/worker.py
Normal file
36
python-sdk/examples/async/worker.py
Normal 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()
|
||||
Reference in New Issue
Block a user