mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-24 02:59:55 -05:00
Merge branch 'main' into feat-durable-execution
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from hatchet_sdk import CancelledError, Context, EmptyModel, Hatchet
|
||||
from hatchet_sdk import Context, EmptyModel, Hatchet
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
@@ -40,25 +40,6 @@ def check_flag(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
|
||||
|
||||
|
||||
# > Handling cancelled error
|
||||
@cancellation_workflow.task()
|
||||
async def my_task(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
try:
|
||||
await asyncio.sleep(10)
|
||||
except CancelledError as e:
|
||||
# Handle parent cancellation - i.e. perform cleanup, then re-raise
|
||||
print(f"Parent Task cancelled: {e.reason}")
|
||||
# Always re-raise CancelledError so Hatchet can properly handle the cancellation
|
||||
raise
|
||||
except Exception as e:
|
||||
# This will NOT catch CancelledError
|
||||
print(f"Other error: {e}")
|
||||
raise
|
||||
return {"error": "Task should have been cancelled"}
|
||||
|
||||
|
||||
|
||||
|
||||
def main() -> None:
|
||||
worker = hatchet.worker("cancellation-worker", workflows=[cancellation_workflow])
|
||||
worker.start()
|
||||
|
||||
Generated
+4
-4
@@ -473,14 +473,14 @@ setuptools = "*"
|
||||
|
||||
[[package]]
|
||||
name = "hatchet-sdk"
|
||||
version = "1.24.0"
|
||||
version = "1.25.0"
|
||||
description = "This is the official Python SDK for Hatchet, a distributed, fault-tolerant task queue. The SDK allows you to easily integrate Hatchet's task scheduling and workflow orchestration capabilities into your Python applications."
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.10"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "hatchet_sdk-1.24.0-py3-none-any.whl", hash = "sha256:6719947bcf3ee954966f5c403f3217b05f3a8829a54eddc3a12c982863d53c4c"},
|
||||
{file = "hatchet_sdk-1.24.0.tar.gz", hash = "sha256:e39bdb4e7013e98f5354dba046cfe14f9284bf835a2f0ca67613efadcac3e180"},
|
||||
{file = "hatchet_sdk-1.25.0-py3-none-any.whl", hash = "sha256:d89ec0183e6593b1f6665fd06c621192d04fceaceaf296f99408be695034954f"},
|
||||
{file = "hatchet_sdk-1.25.0.tar.gz", hash = "sha256:0718e67fdedabde80f50404bb395165eb1b178825a94eb4b1752843eae359e1f"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -1125,4 +1125,4 @@ propcache = ">=0.2.0"
|
||||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "665009b2127a5e046ab48cb29fac59dd00bf17ab45f53a8c897bf8bf62d6bc57"
|
||||
content-hash = "4088ec7612a4f750b19883f71a1a9840f20bd06933a1117c7e79e14afac06e9c"
|
||||
|
||||
@@ -8,7 +8,7 @@ package-mode = false
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
hatchet-sdk = "1.24.0"
|
||||
hatchet-sdk = "1.25.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# > Simple
|
||||
from hatchet_sdk import Context, DurableContext, EmptyModel, Hatchet
|
||||
from hatchet_sdk import Context, EmptyModel, Hatchet
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
@@ -10,8 +10,7 @@ def simple(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
|
||||
|
||||
@hatchet.durable_task()
|
||||
async def simple_durable(input: EmptyModel, ctx: DurableContext) -> dict[str, str]:
|
||||
# durable tasks should be async
|
||||
def simple_durable(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
||||
return {"result": "Hello, world!"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user