Files
hatchet/python-sdk/examples/timeout/worker.py
abelanger5 40760e0951 chore(python-sdk): improved thread cancellation handling, docs, and custom sleep method (#134)
* feat: timeout on python steps

* chore(python-sdk): improved thread handling and docs

* docs: default timeout
2024-01-27 22:14:48 -05:00

27 lines
651 B
Python

from hatchet_sdk import Hatchet
from dotenv import load_dotenv
load_dotenv()
hatchet = Hatchet(debug=True)
@hatchet.workflow(on_events=["user:create"])
class TimeoutWorkflow:
def __init__(self):
self.my_value = "test"
@hatchet.step(timeout='4s')
def timeout(self, context):
try:
print("started step2")
context.sleep(5)
print("finished step2")
except Exception as e:
print("caught an exception: " + str(e))
raise e
workflow = TimeoutWorkflow()
worker = hatchet.worker('timeout-worker', max_threads=4)
worker.register_workflow(workflow)
worker.start()