Files
hatchet/python-sdk/examples/simple/worker.py
abelanger5 6ea38a99f2 feat: support maxRuns parameter on workers (#195)
* feat: round robin queueing

* feat: configurable max runs per worker

* fix: address PR review

* docs for max runs and group round robin
2024-02-26 00:48:46 -05:00

35 lines
829 B
Python

from hatchet_sdk import Hatchet, Context
from dotenv import load_dotenv
load_dotenv()
hatchet = Hatchet(debug=True)
@hatchet.workflow(on_events=["user:create"])
class MyWorkflow:
def __init__(self):
self.my_value = "test"
@hatchet.step()
def step1(self, context: Context):
test = context.playground("test", "test")
test2 = context.playground("test2", 100)
test3 = context.playground("test3", None)
print(test)
print(test2)
print("executed step1")
pass
@hatchet.step(parents=["step1"],timeout='4s')
def step2(self, context):
print("started step2")
context.sleep(1)
print("finished step2")
workflow = MyWorkflow()
worker = hatchet.worker('test-worker', max_runs=4)
worker.register_workflow(workflow)
worker.start()