Skip to content

Commit 562851f

Browse files
committed
Use Worker::validate_namespace from sdk-core to get namespace information
1 parent 9b40dec commit 562851f

6 files changed

Lines changed: 101 additions & 11 deletions

File tree

temporalio/bridge/proto/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ActivitySlotInfo,
44
ActivityTaskCompletion,
55
LocalActivitySlotInfo,
6+
NamespaceInfo,
67
NexusSlotInfo,
78
WorkflowSlotInfo,
89
)
@@ -12,6 +13,7 @@
1213
"ActivitySlotInfo",
1314
"ActivityTaskCompletion",
1415
"LocalActivitySlotInfo",
16+
"NamespaceInfo",
1517
"NexusSlotInfo",
1618
"WorkflowSlotInfo",
1719
]

temporalio/bridge/proto/core_interface_pb2.py

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporalio/bridge/proto/core_interface_pb2.pyi

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,54 @@ class NexusSlotInfo(google.protobuf.message.Message):
165165
) -> None: ...
166166

167167
global___NexusSlotInfo = NexusSlotInfo
168+
169+
class NamespaceInfo(google.protobuf.message.Message):
170+
"""Info about a namespace"""
171+
172+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
173+
174+
class Limits(google.protobuf.message.Message):
175+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
176+
177+
BLOB_SIZE_LIMIT_ERROR_FIELD_NUMBER: builtins.int
178+
MEMO_SIZE_LIMIT_ERROR_FIELD_NUMBER: builtins.int
179+
blob_size_limit_error: builtins.int
180+
"""Maximum size in bytes for payload fields in workflow history events
181+
(e.g., workflow/activity inputs and results, failure details, signal payloads).
182+
When exceeded, the server will reject the operation with an error.
183+
"""
184+
memo_size_limit_error: builtins.int
185+
"""Maximum total memo size in bytes per workflow execution."""
186+
def __init__(
187+
self,
188+
*,
189+
blob_size_limit_error: builtins.int = ...,
190+
memo_size_limit_error: builtins.int = ...,
191+
) -> None: ...
192+
def ClearField(
193+
self,
194+
field_name: typing_extensions.Literal[
195+
"blob_size_limit_error",
196+
b"blob_size_limit_error",
197+
"memo_size_limit_error",
198+
b"memo_size_limit_error",
199+
],
200+
) -> None: ...
201+
202+
LIMITS_FIELD_NUMBER: builtins.int
203+
@property
204+
def limits(self) -> global___NamespaceInfo.Limits:
205+
"""Namespace configured limits"""
206+
def __init__(
207+
self,
208+
*,
209+
limits: global___NamespaceInfo.Limits | None = ...,
210+
) -> None: ...
211+
def HasField(
212+
self, field_name: typing_extensions.Literal["limits", b"limits"]
213+
) -> builtins.bool: ...
214+
def ClearField(
215+
self, field_name: typing_extensions.Literal["limits", b"limits"]
216+
) -> None: ...
217+
218+
global___NamespaceInfo = NamespaceInfo

temporalio/bridge/src/worker.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ pub fn new_replay_worker<'a>(
543543

544544
#[pymethods]
545545
impl WorkerRef {
546-
fn validate<'p>(&self, py: Python<'p>) -> PyResult<Bound<PyAny, 'p>> {
546+
fn validate_namespace<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
547547
self.runtime.assert_same_process("use worker")?;
548548
let worker = self.worker.as_ref().unwrap().clone();
549549
// Set custom slot supplier task locals so they can run futures.
@@ -555,11 +555,15 @@ impl WorkerRef {
555555
.expect("must only be set once");
556556

557557
self.runtime.future_into_py(py, async move {
558-
worker
559-
.validate()
560-
.await
561-
.context("Worker validation failed")
562-
.map_err(Into::into)
558+
let bytes = match worker.validate_namespace().await {
559+
Ok(info) => info.encode_to_vec(),
560+
Err(err) => {
561+
return Err(PyRuntimeError::new_err(format!(
562+
"Worker validation failed: {err}"
563+
)))
564+
}
565+
};
566+
Ok(bytes)
563567
})
564568
}
565569

temporalio/bridge/worker.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
from temporalio.bridge.temporal_sdk_bridge import (
2626
CustomSlotSupplier as BridgeCustomSlotSupplier,
2727
)
28-
from temporalio.bridge.temporal_sdk_bridge import PollShutdownError # type: ignore
28+
from temporalio.bridge.temporal_sdk_bridge import (
29+
PollShutdownError, # type: ignore # noqa: F401
30+
)
2931
from temporalio.worker._command_aware_visitor import CommandAwarePayloadVisitor
3032

3133

@@ -194,9 +196,13 @@ def __init__(self, ref: temporalio.bridge.temporal_sdk_bridge.WorkerRef) -> None
194196
"""Create SDK core worker from a bridge worker."""
195197
self._ref = ref
196198

197-
async def validate(self) -> None:
199+
async def validate_namespace(
200+
self,
201+
) -> temporalio.bridge.proto.NamespaceInfo:
198202
"""Validate the bridge worker."""
199-
await self._ref.validate() # type: ignore[reportOptionalMemberAccess]
203+
return temporalio.bridge.proto.NamespaceInfo.FromString(
204+
await self._ref.validate_namespace() # type: ignore[reportOptionalMemberAccess]
205+
)
200206

201207
async def poll_workflow_activation(
202208
self,

temporalio/worker/_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def make_lambda(plugin: Plugin, next: Callable[[Worker], Awaitable[None]]):
715715

716716
async def _run(self):
717717
# Eagerly validate which will do a namespace check in Core
718-
await self._bridge_worker.validate()
718+
_ = await self._bridge_worker.validate_namespace()
719719

720720
if self._started:
721721
raise RuntimeError("Already started")

0 commit comments

Comments
 (0)