mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-02 22:59:59 -06:00
* chore: bad project path * fix: remove tickerId for replay * feat: cancel from request * feat: cancel button in UI * chore: rm comment * fix: build error * chore: reason case * chore: reason string * fix: linting --------- Co-authored-by: gabriel ruttner <gabe@hatchet.run>
29 lines
723 B
Python
29 lines
723 B
Python
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 CancelWorkflow:
|
|
def __init__(self):
|
|
self.my_value = "test"
|
|
|
|
@hatchet.step(timeout='10s', retries=1)
|
|
async def step1(self, context: Context):
|
|
i = 0
|
|
while not context.exit_flag.is_set() and i < 20:
|
|
print(f"Waiting for cancellation {i}")
|
|
await asyncio.sleep(1)
|
|
i += 1
|
|
|
|
if context.exit_flag.is_set():
|
|
print("Cancelled")
|
|
|
|
|
|
workflow = CancelWorkflow()
|
|
worker = hatchet.worker('test-worker', max_runs=4)
|
|
worker.register_workflow(workflow)
|
|
|
|
worker.start() |