Skip to content

Commit

Permalink
Update to Python SDK 1.7.0 (#527)
Browse files Browse the repository at this point in the history
* Support for new Python update work

* Add WorkflowUpdateRPCTimeoutOrCancelledError support

* Update to Python SDK 1.7.0

---------

Co-authored-by: Chad Retz <[email protected]>
  • Loading branch information
dandavison and cretz authored Aug 20, 2024
1 parent 1a7057a commit cb4b5a4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
go_latest: '1.28.1'
typescript_latest: '1.10.3'
java_latest: '1.25.0'
python_latest: '1.6.0'
python_latest: '1.7.0'
csharp_latest: '1.2.0'
steps:
- run: 'echo noop'
Expand Down
28 changes: 22 additions & 6 deletions features/update/async_accepted/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
from datetime import timedelta

from temporalio import activity, workflow
from temporalio.client import RPCError, WorkflowHandle, WorkflowUpdateFailedError
from temporalio.client import (
RPCError,
RPCStatusCode,
WorkflowHandle,
WorkflowUpdateFailedError,
WorkflowUpdateRPCTimeoutOrCancelledError,
WorkflowUpdateStage,
)
from temporalio.exceptions import ApplicationError

from harness.python.feature import Runner, register_feature
Expand Down Expand Up @@ -51,7 +58,10 @@ async def check_result(runner: Runner, handle: WorkflowHandle) -> None:
# Issue async update
update_id = "sleepy_update"
update_handle = await handle.start_update(
Workflow.do_maybe_wait_update, True, id=update_id
Workflow.do_maybe_wait_update,
True,
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
id=update_id,
)
await handle.signal(Workflow.unblock)
# There's no API at the moment for directly creating a handle w/o calling start update since
Expand All @@ -61,7 +71,10 @@ async def check_result(runner: Runner, handle: WorkflowHandle) -> None:
# Async update which throws
fail_update_id = "failing_update"
update_handle = await handle.start_update(
Workflow.do_maybe_wait_update, False, id=fail_update_id
Workflow.do_maybe_wait_update,
False,
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
id=fail_update_id,
)
try:
await update_handle.result()
Expand All @@ -74,13 +87,16 @@ async def check_result(runner: Runner, handle: WorkflowHandle) -> None:
# Verify timeouts work, but we can only use RPC timeout for now, because of ☝️
timeout_update_id = "timeout_update"
update_handle = await handle.start_update(
Workflow.do_maybe_wait_update, True, id=timeout_update_id
Workflow.do_maybe_wait_update,
True,
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
id=timeout_update_id,
)
try:
await update_handle.result(rpc_timeout=timedelta(seconds=1))
raise RuntimeError("Should have failed")
except RPCError as err:
assert "Timeout expired" == err.message
except WorkflowUpdateRPCTimeoutOrCancelledError:
pass

await handle.signal(Workflow.finish)
await handle.result()
Expand Down
18 changes: 15 additions & 3 deletions features/update/basic_async/feature.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from datetime import timedelta

from temporalio import workflow
from temporalio.client import WorkflowHandle, WorkflowUpdateFailedError
from temporalio.client import (
WorkflowHandle,
WorkflowUpdateFailedError,
WorkflowUpdateStage,
)

from harness.python.feature import Runner, register_feature

Expand Down Expand Up @@ -35,15 +39,23 @@ def my_validate(self, arg: str):

async def checker(runner: Runner, handle: WorkflowHandle):
await runner.skip_if_update_unsupported()
bad_update_handle = await handle.start_update(Workflow.my_update, "bad-update-arg")
bad_update_handle = await handle.start_update(
Workflow.my_update,
"bad-update-arg",
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
)
try:
await bad_update_handle.result()
except WorkflowUpdateFailedError:
pass
else:
assert False, "Expected Update to be rejected due to validation failure"

update_handle = await handle.start_update(Workflow.my_update, "update-arg")
update_handle = await handle.start_update(
Workflow.my_update,
"update-arg",
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
)
update_result = await update_handle.result()
assert update_result == "update-result"
result = await handle.result()
Expand Down
18 changes: 14 additions & 4 deletions features/update/deduplication/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import timedelta

from temporalio import activity, workflow
from temporalio.client import WorkflowHandle
from temporalio.client import WorkflowHandle, WorkflowUpdateStage

from harness.python.feature import Runner, register_feature

Expand Down Expand Up @@ -37,15 +37,25 @@ async def start(runner: Runner) -> WorkflowHandle:

async def check_result(runner: Runner, handle: WorkflowHandle) -> None:
update_id = "incrementer"
h1 = await handle.start_update(Workflow.inc_counter, id=update_id)
h2 = await handle.start_update(Workflow.inc_counter, id=update_id)
h1 = await handle.start_update(
Workflow.inc_counter,
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
id=update_id,
)
h2 = await handle.start_update(
Workflow.inc_counter,
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
id=update_id,
)
await handle.signal(Workflow.unblock)
results = await asyncio.gather(h1.result(), h2.result())
assert results[0] == 1
assert results[1] == 1

# This only needs to start to unblock the workflow
await handle.start_update(Workflow.inc_counter)
await handle.start_update(
Workflow.inc_counter, wait_for_stage=WorkflowUpdateStage.ACCEPTED
)

# There should be two accepted updates, and only one of them should be completed with the set id
total_updates = 0
Expand Down
33 changes: 9 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.8"
temporalio = "^1.6.0"
temporalio = "^1.7.0"

[tool.poetry.dev-dependencies]
mypy = "^0.961"
Expand Down

0 comments on commit cb4b5a4

Please sign in to comment.