mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-21 00:59:50 -05:00
feat(py-sdk): event streaming and manual triggering (#152)
* hotfix: add repository for npm publish * chore: generate protos * feat: trigger workflow * fix: remove tenant id from schedule workflow * fix: logging * feat: run returns workflow_run_id * feat: listen for run events * feat: listener calls handler * chore: address review comment
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
from hatchet_sdk import new_client
|
||||
from dotenv import load_dotenv
|
||||
import json
|
||||
|
||||
load_dotenv()
|
||||
|
||||
client = new_client()
|
||||
|
||||
workflowRunId = client.admin.run_workflow("ManualTriggerWorkflow", {
|
||||
"test": "test"
|
||||
})
|
||||
|
||||
client.listener.on(workflowRunId, lambda event: print(
|
||||
'EVENT: ' + event.type + ' ' + json.dumps(event.payload)))
|
||||
|
||||
# TODO - need to hangup the listener if the workflow is completed
|
||||
@@ -0,0 +1,28 @@
|
||||
from hatchet_sdk import Hatchet
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
|
||||
@hatchet.workflow(on_events=["user:create"])
|
||||
class ManualTriggerWorkflow:
|
||||
@hatchet.step()
|
||||
def step1(self, context):
|
||||
print("executed step1")
|
||||
return {"step1": "data1"}
|
||||
|
||||
@hatchet.step(parents=["step1"], timeout='4s')
|
||||
def step2(self, context):
|
||||
print("started step2")
|
||||
context.sleep(1)
|
||||
print("finished step2")
|
||||
return {"step2": "data2"}
|
||||
|
||||
|
||||
workflow = ManualTriggerWorkflow()
|
||||
worker = hatchet.worker('test-worker', max_threads=4)
|
||||
worker.register_workflow(workflow)
|
||||
|
||||
worker.start()
|
||||
Reference in New Issue
Block a user