Skip to content

Commit aac8dcd

Browse files
committed
Revert "Wording from core protos"
This reverts commit d5e6dad.
1 parent 98d879e commit aac8dcd

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

temporalio/workflow.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5119,25 +5119,29 @@ def _to_proto(self) -> temporalio.bridge.proto.common.VersioningIntent.ValueType
51195119

51205120

51215121
class NexusOperationCancellationType(IntEnum):
5122-
"""Controls at which point to report back to lang when a nexus operation is
5123-
cancelled."""
5122+
"""Defines behavior of the parent workflow when CancellationScope that wraps Nexus operation
5123+
is canceled. The result of the cancellation independently of the type is a
5124+
CanceledFailure thrown from the Nexus operation method. If the caller exits without waiting, the
5125+
cancellation request may not be delivered to the handler, regardless of indicated cancellation
5126+
type.
5127+
"""
51245128

5125-
WAIT_CANCELLATION_COMPLETED = 0
5126-
"""Wait for operation cancellation completion. Default."""
5129+
WAIT_COMPLETED = 0
5130+
"""Wait for operation completion. Operation may or may not complete as cancelled. Default."""
51275131

51285132
ABANDON = 1
5129-
"""Do not request cancellation of the nexus operation if already scheduled."""
5133+
"""Do not request cancellation of the operation."""
51305134

51315135
TRY_CANCEL = 2
5132-
"""Initiate a cancellation request for the Nexus operation and immediately report
5133-
cancellation to the caller. Note that it doesn't guarantee that cancellation is
5134-
delivered to the operation if calling workflow exits before the delivery is done. If
5135-
you want to ensure that cancellation is delivered to the operation, use
5136-
WAIT_CANCELLATION_REQUESTED."""
5136+
"""Initiate a cancellation request and immediately report cancellation to the caller. Note that it
5137+
doesn't guarantee that cancellation is delivered to the operation handler if the caller exits
5138+
before the delivery is done.
5139+
"""
51375140

5138-
WAIT_CANCELLATION_REQUESTED = 3
5139-
"""Request cancellation of the operation and wait for confirmation that the request
5140-
was received."""
5141+
WAIT_REQUESTED = 3
5142+
"""Request cancellation of the operation and wait for confirmation that the request was received.
5143+
Doesn't wait for actual cancellation.
5144+
"""
51415145

51425146

51435147
class NexusClient(ABC, Generic[ServiceT]):
@@ -5170,7 +5174,7 @@ async def start_operation(
51705174
*,
51715175
output_type: Optional[type[OutputT]] = None,
51725176
schedule_to_close_timeout: Optional[timedelta] = None,
5173-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5177+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
51745178
headers: Optional[Mapping[str, str]] = None,
51755179
) -> NexusOperationHandle[OutputT]: ...
51765180

@@ -5184,7 +5188,7 @@ async def start_operation(
51845188
*,
51855189
output_type: Optional[type[OutputT]] = None,
51865190
schedule_to_close_timeout: Optional[timedelta] = None,
5187-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5191+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
51885192
headers: Optional[Mapping[str, str]] = None,
51895193
) -> NexusOperationHandle[OutputT]: ...
51905194

@@ -5201,7 +5205,7 @@ async def start_operation(
52015205
*,
52025206
output_type: Optional[type[OutputT]] = None,
52035207
schedule_to_close_timeout: Optional[timedelta] = None,
5204-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5208+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52055209
headers: Optional[Mapping[str, str]] = None,
52065210
) -> NexusOperationHandle[OutputT]: ...
52075211

@@ -5218,7 +5222,7 @@ async def start_operation(
52185222
*,
52195223
output_type: Optional[type[OutputT]] = None,
52205224
schedule_to_close_timeout: Optional[timedelta] = None,
5221-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5225+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52225226
headers: Optional[Mapping[str, str]] = None,
52235227
) -> NexusOperationHandle[OutputT]: ...
52245228

@@ -5235,7 +5239,7 @@ async def start_operation(
52355239
*,
52365240
output_type: Optional[type[OutputT]] = None,
52375241
schedule_to_close_timeout: Optional[timedelta] = None,
5238-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5242+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52395243
headers: Optional[Mapping[str, str]] = None,
52405244
) -> NexusOperationHandle[OutputT]: ...
52415245

@@ -5247,6 +5251,7 @@ async def start_operation(
52475251
*,
52485252
output_type: Optional[type[OutputT]] = None,
52495253
schedule_to_close_timeout: Optional[timedelta] = None,
5254+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52505255
headers: Optional[Mapping[str, str]] = None,
52515256
) -> Any:
52525257
"""Start a Nexus operation and return its handle.
@@ -5276,7 +5281,7 @@ async def execute_operation(
52765281
*,
52775282
output_type: Optional[type[OutputT]] = None,
52785283
schedule_to_close_timeout: Optional[timedelta] = None,
5279-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5284+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52805285
headers: Optional[Mapping[str, str]] = None,
52815286
) -> OutputT: ...
52825287

@@ -5290,7 +5295,7 @@ async def execute_operation(
52905295
*,
52915296
output_type: Optional[type[OutputT]] = None,
52925297
schedule_to_close_timeout: Optional[timedelta] = None,
5293-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5298+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
52945299
headers: Optional[Mapping[str, str]] = None,
52955300
) -> OutputT: ...
52965301

@@ -5307,6 +5312,7 @@ async def execute_operation(
53075312
*,
53085313
output_type: Optional[type[OutputT]] = None,
53095314
schedule_to_close_timeout: Optional[timedelta] = None,
5315+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
53105316
headers: Optional[Mapping[str, str]] = None,
53115317
) -> OutputT: ...
53125318

@@ -5323,7 +5329,7 @@ async def execute_operation(
53235329
*,
53245330
output_type: Optional[type[OutputT]] = None,
53255331
schedule_to_close_timeout: Optional[timedelta] = None,
5326-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5332+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
53275333
headers: Optional[Mapping[str, str]] = None,
53285334
) -> OutputT: ...
53295335

@@ -5340,7 +5346,7 @@ async def execute_operation(
53405346
*,
53415347
output_type: Optional[type[OutputT]] = None,
53425348
schedule_to_close_timeout: Optional[timedelta] = None,
5343-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5349+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
53445350
headers: Optional[Mapping[str, str]] = None,
53455351
) -> OutputT: ...
53465352

@@ -5352,6 +5358,7 @@ async def execute_operation(
53525358
*,
53535359
output_type: Optional[type[OutputT]] = None,
53545360
schedule_to_close_timeout: Optional[timedelta] = None,
5361+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
53555362
headers: Optional[Mapping[str, str]] = None,
53565363
) -> Any:
53575364
"""Execute a Nexus operation and return its result.
@@ -5403,7 +5410,7 @@ async def start_operation(
54035410
*,
54045411
output_type: Optional[type] = None,
54055412
schedule_to_close_timeout: Optional[timedelta] = None,
5406-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5413+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
54075414
headers: Optional[Mapping[str, str]] = None,
54085415
) -> Any:
54095416
return (
@@ -5426,7 +5433,7 @@ async def execute_operation(
54265433
*,
54275434
output_type: Optional[type] = None,
54285435
schedule_to_close_timeout: Optional[timedelta] = None,
5429-
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
5436+
cancellation_type: NexusOperationCancellationType = NexusOperationCancellationType.WAIT_COMPLETED,
54305437
headers: Optional[Mapping[str, str]] = None,
54315438
) -> Any:
54325439
handle = await self.start_operation(

tests/nexus/test_workflow_caller_cancellation_types.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import uuid
33
from dataclasses import dataclass
4-
from typing import Optional
4+
from typing import Any, Optional
55

66
import nexusrpc
77
import pytest
@@ -41,7 +41,6 @@ class ServiceHandler:
4141
async def workflow_op(
4242
self, ctx: nexus.WorkflowRunOperationContext, _input: None
4343
) -> nexus.WorkflowHandle[None]:
44-
print("🟢 ServiceHandler.workflow_op")
4544
return await ctx.start_workflow(
4645
HandlerWorkflow.run,
4746
id="handler-wf-" + str(uuid.uuid4()),
@@ -74,11 +73,15 @@ async def run(self, input: Input) -> CancellationResult:
7473
Test cancellation type = WAIT_CANCELLATION_COMPLETED.
7574
The operation should have been canceled before the nexus operation failure exception is raised.
7675
"""
77-
kwargs = {}
78-
if input.cancellation_type is not None:
79-
kwargs["cancellation_type"] = input.cancellation_type
80-
op_handle = await self.nexus_client.start_operation(
81-
Service.workflow_op, input=None, **kwargs
76+
77+
op_handle = await (
78+
self.nexus_client.start_operation(
79+
Service.workflow_op,
80+
input=None,
81+
cancellation_type=input.cancellation_type,
82+
)
83+
if input.cancellation_type
84+
else self.nexus_client.start_operation(Service.workflow_op, input=None)
8285
)
8386
op_handle.cancel()
8487
try:
@@ -97,7 +100,9 @@ async def check_behavior_for_wait_cancellation_completed(
97100
Check that backing workflow received a cancellation request and has been canceled (is
98101
not running)
99102
"""
100-
nexus_handle = nexus.WorkflowHandle.from_token(operation_token)
103+
nexus_handle: nexus.WorkflowHandle[Any] = nexus.WorkflowHandle.from_token(
104+
operation_token
105+
)
101106
wf_handle = nexus_handle._to_client_workflow_handle(client)
102107

103108
assert (await wf_handle.describe()).status == WorkflowExecutionStatus.CANCELED
@@ -111,7 +116,9 @@ async def check_behavior_for_abandon(client: Client, operation_token: str) -> No
111116
Check that backing workflow has not received a cancellation request and has not been
112117
canceled (is still running) and does not receive a cancellation request.
113118
"""
114-
nexus_handle = nexus.WorkflowHandle.from_token(operation_token)
119+
nexus_handle: nexus.WorkflowHandle[Any] = nexus.WorkflowHandle.from_token(
120+
operation_token
121+
)
115122
wf_handle = nexus_handle._to_client_workflow_handle(client)
116123

117124
assert (await wf_handle.describe()).status == WorkflowExecutionStatus.RUNNING
@@ -128,7 +135,9 @@ async def check_behavior_for_wait_cancellation_requested(
128135
Check that backing workflow received a cancellation request but has not been canceled
129136
(is still running)
130137
"""
131-
nexus_handle = nexus.WorkflowHandle.from_token(operation_token)
138+
nexus_handle: nexus.WorkflowHandle[Any] = nexus.WorkflowHandle.from_token(
139+
operation_token
140+
)
132141
wf_handle = nexus_handle._to_client_workflow_handle(client)
133142

134143
assert await _has_event(
@@ -146,7 +155,9 @@ async def check_behavior_for_try_cancel(client: Client, operation_token: str) ->
146155
Check that backing workflow has not received a cancellation request initially
147156
and is still running, but eventually does receive a cancellation request
148157
"""
149-
nexus_handle = nexus.WorkflowHandle.from_token(operation_token)
158+
nexus_handle: nexus.WorkflowHandle[Any] = nexus.WorkflowHandle.from_token(
159+
operation_token
160+
)
150161
wf_handle = nexus_handle._to_client_workflow_handle(client)
151162
assert (await wf_handle.describe()).status == WorkflowExecutionStatus.RUNNING
152163

@@ -161,10 +172,10 @@ async def check_behavior_for_try_cancel(client: Client, operation_token: str) ->
161172
"cancellation_type",
162173
[
163174
None,
164-
workflow.NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED.name,
175+
workflow.NexusOperationCancellationType.WAIT_COMPLETED.name,
165176
workflow.NexusOperationCancellationType.ABANDON.name,
166177
workflow.NexusOperationCancellationType.TRY_CANCEL.name,
167-
workflow.NexusOperationCancellationType.WAIT_CANCELLATION_REQUESTED.name,
178+
workflow.NexusOperationCancellationType.WAIT_REQUESTED.name,
168179
],
169180
)
170181
async def test_cancellation_type(
@@ -201,14 +212,14 @@ async def test_cancellation_type(
201212

202213
if input.cancellation_type in [
203214
None,
204-
workflow.NexusOperationCancellationType.WAIT_CANCELLATION_COMPLETED,
215+
workflow.NexusOperationCancellationType.WAIT_COMPLETED,
205216
]:
206217
await check_behavior_for_wait_cancellation_completed(client, op_token)
207218
elif input.cancellation_type == workflow.NexusOperationCancellationType.ABANDON:
208219
await check_behavior_for_abandon(client, op_token)
209220
elif (
210221
input.cancellation_type
211-
== workflow.NexusOperationCancellationType.WAIT_CANCELLATION_REQUESTED
222+
== workflow.NexusOperationCancellationType.WAIT_REQUESTED
212223
):
213224
await check_behavior_for_wait_cancellation_requested(client, op_token)
214225
elif (

0 commit comments

Comments
 (0)