Skip to content

Commit 29870b1

Browse files
committed
Test
1 parent be7d269 commit 29870b1

File tree

10 files changed

+401
-43
lines changed

10 files changed

+401
-43
lines changed

temporalio/bridge/src/client.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,40 @@ impl ClientRef {
139139
"delete_schedule" => {
140140
rpc_call!(retry_client, call, delete_schedule)
141141
}
142+
"delete_worker_deployment" => {
143+
rpc_call!(retry_client, call, delete_worker_deployment)
144+
}
145+
"delete_worker_deployment_version" => {
146+
rpc_call!(retry_client, call, delete_worker_deployment_version)
147+
}
142148
"delete_workflow_execution" => {
143149
rpc_call!(retry_client, call, delete_workflow_execution)
144150
}
151+
"describe_batch_operation" => {
152+
rpc_call!(retry_client, call, describe_batch_operation)
153+
}
154+
"describe_deployment" => {
155+
rpc_call!(retry_client, call, describe_deployment)
156+
}
145157
"deprecate_namespace" => rpc_call!(retry_client, call, deprecate_namespace),
146158
"describe_namespace" => rpc_call!(retry_client, call, describe_namespace),
147159
"describe_schedule" => rpc_call!(retry_client, call, describe_schedule),
148160
"describe_task_queue" => rpc_call!(retry_client, call, describe_task_queue),
161+
"describe_worker_deployment" => {
162+
rpc_call!(retry_client, call, describe_worker_deployment)
163+
}
164+
"describe_worker_deployment_version" => {
165+
rpc_call!(retry_client, call, describe_worker_deployment_version)
166+
}
149167
"describe_workflow_execution" => {
150168
rpc_call!(retry_client, call, describe_workflow_execution)
151169
}
152170
"execute_multi_operation" => rpc_call!(retry_client, call, execute_multi_operation),
153171
"get_cluster_info" => rpc_call!(retry_client, call, get_cluster_info),
172+
"get_current_deployment" => rpc_call!(retry_client, call, get_current_deployment),
173+
"get_deployment_reachability" => {
174+
rpc_call!(retry_client, call, get_deployment_reachability)
175+
}
154176
"get_search_attributes" => {
155177
rpc_call!(retry_client, call, get_search_attributes)
156178
}
@@ -176,6 +198,9 @@ impl ClientRef {
176198
"list_closed_workflow_executions" => {
177199
rpc_call!(retry_client, call, list_closed_workflow_executions)
178200
}
201+
"list_deployments" => {
202+
rpc_call!(retry_client, call, list_deployments)
203+
}
179204
"list_namespaces" => rpc_call!(retry_client, call, list_namespaces),
180205
"list_open_workflow_executions" => {
181206
rpc_call!(retry_client, call, list_open_workflow_executions)
@@ -189,6 +214,9 @@ impl ClientRef {
189214
"list_task_queue_partitions" => {
190215
rpc_call!(retry_client, call, list_task_queue_partitions)
191216
}
217+
"list_worker_deployments" => {
218+
rpc_call!(retry_client, call, list_worker_deployments)
219+
}
192220
"list_workflow_executions" => {
193221
rpc_call!(retry_client, call, list_workflow_executions)
194222
}
@@ -258,6 +286,18 @@ impl ClientRef {
258286
"scan_workflow_executions" => {
259287
rpc_call!(retry_client, call, scan_workflow_executions)
260288
}
289+
"set_current_deployment" => {
290+
rpc_call!(retry_client, call, set_current_deployment)
291+
}
292+
"set_worker_deployment_current_version" => {
293+
rpc_call!(retry_client, call, set_worker_deployment_current_version)
294+
}
295+
"set_worker_deployment_ramping_version" => {
296+
rpc_call!(retry_client, call, set_worker_deployment_ramping_version)
297+
}
298+
"shutdown_worker" => {
299+
rpc_call!(retry_client, call, shutdown_worker)
300+
}
261301
"signal_with_start_workflow_execution" => {
262302
rpc_call!(retry_client, call, signal_with_start_workflow_execution)
263303
}
@@ -274,6 +314,13 @@ impl ClientRef {
274314
rpc_call_on_trait!(retry_client, call, WorkflowService, update_namespace)
275315
}
276316
"update_schedule" => rpc_call!(retry_client, call, update_schedule),
317+
"update_worker_deployment_version_metadata" => {
318+
rpc_call!(
319+
retry_client,
320+
call,
321+
update_worker_deployment_version_metadata
322+
)
323+
}
277324
"update_workflow_execution" => {
278325
rpc_call!(retry_client, call, update_workflow_execution)
279326
}

temporalio/bridge/src/worker.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ pub struct WorkerConfig {
6666
/// Recreates [temporal_sdk_core_api::worker::WorkerVersioningStrategy]
6767
#[derive(FromPyObject)]
6868
pub enum WorkerVersioningStrategy {
69-
None { build_id: String },
70-
WorkerDeploymentBased(WorkerDeploymentOptions),
71-
LegacyBuildIdBased { build_id: String },
69+
None(WorkerVersioningNone),
70+
DeploymentBased(WorkerDeploymentOptions),
71+
LegacyBuildIdBased(LegacyBuildIdBased),
72+
}
73+
74+
#[derive(FromPyObject)]
75+
pub struct WorkerVersioningNone {
76+
pub build_id: String,
7277
}
7378

7479
/// Recreates [temporal_sdk_core_api::worker::WorkerDeploymentOptions]
@@ -80,6 +85,11 @@ pub struct WorkerDeploymentOptions {
8085
pub default_versioning_behavior: i32,
8186
}
8287

88+
#[derive(FromPyObject)]
89+
pub struct LegacyBuildIdBased {
90+
pub build_id: String,
91+
}
92+
8393
/// Recreates [temporal_sdk_core_api::worker::WorkerDeploymentVersion]
8494
#[derive(FromPyObject)]
8595
pub struct WorkerDeploymentVersion {
@@ -734,28 +744,32 @@ fn convert_versioning_strategy(
734744
strategy: WorkerVersioningStrategy,
735745
) -> temporal_sdk_core_api::worker::WorkerVersioningStrategy {
736746
match strategy {
737-
WorkerVersioningStrategy::None { build_id } => {
738-
temporal_sdk_core_api::worker::WorkerVersioningStrategy::None { build_id }
747+
WorkerVersioningStrategy::None(vn) => {
748+
temporal_sdk_core_api::worker::WorkerVersioningStrategy::None {
749+
build_id: vn.build_id,
750+
}
739751
}
740-
WorkerVersioningStrategy::WorkerDeploymentBased(worker_deployment_options) => {
752+
WorkerVersioningStrategy::DeploymentBased(options) => {
741753
temporal_sdk_core_api::worker::WorkerVersioningStrategy::WorkerDeploymentBased(
742754
temporal_sdk_core_api::worker::WorkerDeploymentOptions {
743755
version: temporal_sdk_core_api::worker::WorkerDeploymentVersion {
744-
deployment_name: worker_deployment_options.version.deployment_name,
745-
build_id: worker_deployment_options.version.build_id,
756+
deployment_name: options.version.deployment_name,
757+
build_id: options.version.build_id,
746758
},
747-
use_worker_versioning: worker_deployment_options.use_worker_versioning,
759+
use_worker_versioning: options.use_worker_versioning,
748760
default_versioning_behavior: Some(
749-
worker_deployment_options
761+
options
750762
.default_versioning_behavior
751763
.try_into()
752764
.unwrap_or_default(),
753765
),
754766
},
755767
)
756768
}
757-
WorkerVersioningStrategy::LegacyBuildIdBased { build_id } => {
758-
temporal_sdk_core_api::worker::WorkerVersioningStrategy::LegacyBuildIdBased { build_id }
769+
WorkerVersioningStrategy::LegacyBuildIdBased(lb) => {
770+
temporal_sdk_core_api::worker::WorkerVersioningStrategy::LegacyBuildIdBased {
771+
build_id: lb.build_id,
772+
}
759773
}
760774
}
761775
}

temporalio/bridge/worker.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ class WorkerVersioningStrategyNone:
8787
build_id: str
8888

8989

90-
@dataclass
91-
class WorkerVersioningStrategyDeploymentBased:
92-
"""Python representation of the Rust struct for configuring a worker versioning strategy deployment-based."""
93-
94-
options: WorkerDeploymentOptions
95-
96-
9790
@dataclass
9891
class WorkerVersioningStrategyLegacyBuildIdBased:
9992
"""Python representation of the Rust struct for configuring a worker versioning strategy legacy Build ID-based."""
@@ -103,7 +96,7 @@ class WorkerVersioningStrategyLegacyBuildIdBased:
10396

10497
WorkerVersioningStrategy: TypeAlias = Union[
10598
WorkerVersioningStrategyNone,
106-
WorkerVersioningStrategyDeploymentBased,
99+
WorkerDeploymentOptions,
107100
WorkerVersioningStrategyLegacyBuildIdBased,
108101
]
109102

temporalio/worker/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@
4242
WorkerTuner,
4343
WorkflowSlotInfo,
4444
)
45-
from ._worker import Worker, WorkerConfig
45+
from ._worker import (
46+
Worker,
47+
WorkerConfig,
48+
WorkerDeploymentOptions,
49+
WorkerDeploymentVersion,
50+
)
4651
from ._workflow_instance import (
4752
UnsandboxedWorkflowRunner,
4853
WorkflowInstance,
@@ -54,6 +59,8 @@
5459
# Primary types
5560
"Worker",
5661
"WorkerConfig",
62+
"WorkerDeploymentOptions",
63+
"WorkerDeploymentVersion",
5764
"Replayer",
5865
"ReplayerConfig",
5966
"WorkflowReplayResult",

temporalio/worker/_worker.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import temporalio.exceptions
3939
import temporalio.runtime
4040
import temporalio.service
41-
from temporalio.common import VersioningBehavior
41+
from temporalio.common import VersioningBehavior, WorkerDeploymentVersion
4242

4343
from ._activity import SharedStateManager, _ActivityWorker
4444
from ._interceptor import Interceptor
@@ -372,9 +372,7 @@ def __init__(
372372
versioning_strategy: temporalio.bridge.worker.WorkerVersioningStrategy
373373
if deployment_options:
374374
versioning_strategy = (
375-
temporalio.bridge.worker.WorkerVersioningStrategyDeploymentBased(
376-
options=deployment_options._to_bridge_worker_deployment_options()
377-
)
375+
deployment_options._to_bridge_worker_deployment_options()
378376
)
379377
elif use_worker_versioning:
380378
build_id = build_id or load_default_build_id()
@@ -712,21 +710,13 @@ class WorkerConfig(TypedDict, total=False):
712710
deployment_options: Optional[WorkerDeploymentOptions]
713711

714712

715-
@dataclass
716-
class WorkerDeploymentVersion:
717-
"""Python representation of the Rust struct for configuring a worker deployment version."""
718-
719-
deployment_name: str
720-
build_id: str
721-
722-
723713
@dataclass
724714
class WorkerDeploymentOptions:
725-
"""Python representation of the Rust struct for configuring a worker deployment options."""
715+
"""Options for configuring the Worker Versioning feature."""
726716

727717
version: WorkerDeploymentVersion
728718
use_worker_versioning: bool
729-
default_versioning_behavior: VersioningBehavior
719+
default_versioning_behavior: VersioningBehavior = VersioningBehavior.UNSPECIFIED
730720

731721
def _to_bridge_worker_deployment_options(
732722
self,

temporalio/worker/_workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ async def _handle_activation(
317317

318318
# Always set the run ID on the completion
319319
completion.run_id = act.run_id
320+
# TODO: Could set versioning behavior here?
320321

321322
# Encode the completion if there's a codec and not cache remove job
322323
if self._data_converter.payload_codec:

temporalio/worker/_workflow_instance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ def activate(
345345
temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion()
346346
)
347347
self._current_completion.successful.SetInParent()
348+
self._current_completion.successful.versioning_behavior = (
349+
self._defn.versioning_behavior._to_proto()
350+
if self._defn.versioning_behavior
351+
else temporalio.api.enums.v1.VersioningBehavior.VERSIONING_BEHAVIOR_UNSPECIFIED
352+
)
348353
self._current_activation_error: Optional[Exception] = None
349354
self._current_build_id = act.build_id_for_current_task
350355
self._current_history_length = act.history_length

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ async def env(env_type: str) -> AsyncGenerator[WorkflowEnvironment, None]:
107107
"system.enableEagerWorkflowStart=true",
108108
"--dynamic-config-value",
109109
"frontend.enableExecuteMultiOperation=true",
110+
"--dynamic-config-value",
111+
"frontend.enableVersioningWorkflowAPIs=true",
112+
"--dynamic-config-value",
113+
"frontend.enableVersioningDataAPIs=true",
114+
"--dynamic-config-value",
115+
"system.enableDeploymentVersions=true",
110116
],
111117
# TODO: Remove after next CLI release
112118
dev_server_download_version="v1.3.1-priority.0",

tests/helpers/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ def new_worker(
4646
)
4747

4848

49+
T = TypeVar("T")
50+
51+
4952
async def assert_eventually(
50-
fn: Callable[[], Awaitable],
53+
fn: Callable[[], Awaitable[T]],
5154
*,
5255
timeout: timedelta = timedelta(seconds=10),
5356
interval: timedelta = timedelta(milliseconds=200),
54-
) -> None:
57+
) -> T:
5558
start_sec = time.monotonic()
5659
while True:
5760
try:
58-
await fn()
59-
return
61+
res = await fn()
62+
return res
6063
except AssertionError:
6164
if timedelta(seconds=time.monotonic() - start_sec) >= timeout:
6265
raise
6366
await asyncio.sleep(interval.total_seconds())
6467

6568

66-
T = TypeVar("T")
67-
68-
6969
async def assert_eq_eventually(
7070
expected: T,
7171
fn: Callable[[], Awaitable[T]],

0 commit comments

Comments
 (0)