Skip to content

Commit 317dd9b

Browse files
authored
Add Versioning Intents to Commands (#342)
1 parent d7238cd commit 317dd9b

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

temporalio/worker/_interceptor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import temporalio.api.common.v1
2323
import temporalio.common
2424
import temporalio.workflow
25+
from temporalio.workflow import VersioningIntent
2526

2627

2728
class Interceptor:
@@ -154,6 +155,7 @@ class ContinueAsNewInput:
154155
memo: Optional[Mapping[str, Any]]
155156
search_attributes: Optional[temporalio.common.SearchAttributes]
156157
headers: Mapping[str, temporalio.api.common.v1.Payload]
158+
versioning_intent: Optional[VersioningIntent]
157159
# The types may be absent
158160
arg_types: Optional[List[Type]]
159161

@@ -226,6 +228,7 @@ class StartActivityInput:
226228
cancellation_type: temporalio.workflow.ActivityCancellationType
227229
headers: Mapping[str, temporalio.api.common.v1.Payload]
228230
disable_eager_execution: bool
231+
versioning_intent: Optional[VersioningIntent]
229232
# The types may be absent
230233
arg_types: Optional[List[Type]]
231234
ret_type: Optional[Type]
@@ -250,6 +253,7 @@ class StartChildWorkflowInput:
250253
memo: Optional[Mapping[str, Any]]
251254
search_attributes: Optional[temporalio.common.SearchAttributes]
252255
headers: Mapping[str, temporalio.api.common.v1.Payload]
256+
versioning_intent: Optional[VersioningIntent]
253257
# The types may be absent
254258
arg_types: Optional[List[Type]]
255259
ret_type: Optional[Type]

temporalio/worker/_workflow_instance.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def workflow_continue_as_new(
669669
retry_policy: Optional[temporalio.common.RetryPolicy],
670670
memo: Optional[Mapping[str, Any]],
671671
search_attributes: Optional[temporalio.common.SearchAttributes],
672+
versioning_intent: Optional[temporalio.workflow.VersioningIntent],
672673
) -> NoReturn:
673674
# Use definition if callable
674675
name: Optional[str] = None
@@ -694,6 +695,7 @@ def workflow_continue_as_new(
694695
search_attributes=search_attributes,
695696
headers={},
696697
arg_types=arg_types,
698+
versioning_intent=versioning_intent,
697699
)
698700
)
699701
# TODO(cretz): Why can't MyPy infer the above never returns?
@@ -820,6 +822,7 @@ def workflow_start_activity(
820822
retry_policy: Optional[temporalio.common.RetryPolicy],
821823
cancellation_type: temporalio.workflow.ActivityCancellationType,
822824
activity_id: Optional[str],
825+
versioning_intent: Optional[temporalio.workflow.VersioningIntent],
823826
) -> temporalio.workflow.ActivityHandle[Any]:
824827
# Get activity definition if it's callable
825828
name: str
@@ -851,6 +854,7 @@ def workflow_start_activity(
851854
disable_eager_execution=self._disable_eager_activity_execution,
852855
arg_types=arg_types,
853856
ret_type=ret_type,
857+
versioning_intent=versioning_intent,
854858
)
855859
)
856860

@@ -871,6 +875,7 @@ async def workflow_start_child_workflow(
871875
cron_schedule: str,
872876
memo: Optional[Mapping[str, Any]],
873877
search_attributes: Optional[temporalio.common.SearchAttributes],
878+
versioning_intent: Optional[temporalio.workflow.VersioningIntent],
874879
) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]:
875880
# Use definition if callable
876881
name: str
@@ -905,6 +910,7 @@ async def workflow_start_child_workflow(
905910
headers={},
906911
arg_types=arg_types,
907912
ret_type=ret_type,
913+
versioning_intent=versioning_intent,
908914
)
909915
)
910916

@@ -1679,6 +1685,10 @@ def _apply_schedule_command(
16791685
command.schedule_activity.do_not_eagerly_execute = (
16801686
self._input.disable_eager_execution
16811687
)
1688+
if self._input.versioning_intent:
1689+
command.schedule_activity.versioning_intent = (
1690+
self._input.versioning_intent._to_proto()
1691+
)
16821692
if isinstance(self._input, StartLocalActivityInput):
16831693
if self._input.local_retry_threshold:
16841694
command.schedule_local_activity.local_retry_threshold.FromTimedelta(
@@ -1810,6 +1820,8 @@ def _apply_start_command(
18101820
"temporalio.bridge.proto.child_workflow.ChildWorkflowCancellationType.ValueType",
18111821
int(self._input.cancellation_type),
18121822
)
1823+
if self._input.versioning_intent:
1824+
v.versioning_intent = self._input.versioning_intent._to_proto()
18131825

18141826
# If request cancel external, result does _not_ have seq
18151827
def _apply_cancel_command(
@@ -1907,6 +1919,8 @@ def _apply_command(
19071919
_encode_search_attributes(
19081920
self._input.search_attributes, v.search_attributes
19091921
)
1922+
if self._input.versioning_intent:
1923+
v.versioning_intent = self._input.versioning_intent._to_proto()
19101924

19111925

19121926
def _encode_search_attributes(

0 commit comments

Comments
 (0)