Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions scripts/gen_payload_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,38 @@
from temporalio.converter._payload_converter import _get_transfer_type_converter


def discover_system_nexus_roots() -> list[Descriptor]:
module_path = base_dir / "temporalio" / "nexus" / "system" / "workflow_service"
spec = spec_from_file_location(
"temporalio_nexus_system_workflow_service",
module_path / "__init__.py",
submodule_search_locations=[str(module_path)],
)
if spec is None or spec.loader is None:
raise RuntimeError(f"Cannot load generated system service from {module_path}")
module = module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
def discover_system_nexus_services() -> list[type]:
services: list[type] = []
system_dir = base_dir / "temporalio" / "nexus" / "system"
for module_path in sorted(path.parent for path in system_dir.glob("*/services.py")):
spec = spec_from_file_location(
f"temporalio_nexus_system_{module_path.name}",
module_path / "__init__.py",
submodule_search_locations=[str(module_path)],
)
if spec is None or spec.loader is None:
raise RuntimeError(
f"Cannot load generated system service from {module_path}"
)
module = module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
services.extend(
value
for value in vars(module.services).values()
if isinstance(value, type) and nexusrpc.get_service_definition(value)
)
return services


def discover_system_nexus_roots() -> list[Descriptor]:
roots: list[Descriptor] = []
for annotation in get_type_hints(module._services.WorkflowService).values():
annotations = [
annotation
for service in discover_system_nexus_services()
for annotation in get_type_hints(service).values()
]
for annotation in annotations:
if get_origin(annotation) is not nexusrpc.Operation:
continue
for operation_type in get_args(annotation):
Expand Down
13 changes: 13 additions & 0 deletions temporalio/bridge/Cargo.lock

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

1 change: 1 addition & 0 deletions temporalio/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ temporalio-sdk-core = { version = "0.12.0", path = "./sdk-core/crates/sdk-core",
"envconfig",
"prometheus",
] }
temporalio-streams = { version = "0.1.0", path = "./sdk-core/crates/streams" }
tokio = "1.26"
# Matches the sdk-core client crate's rustls stack; used to build the custom
# server certificate verifier for TLSConfig.verification_server_name.
Expand Down
73 changes: 73 additions & 0 deletions temporalio/bridge/_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ async def _visit_coresdk_workflow_activation_ResolveNexusOperation(
if o.HasField("result"):
await self._visit_coresdk_nexus_NexusOperationResult(fs, o.result)

async def _visit_coresdk_workflow_activation_ResolveStreamAppend(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
self, fs: VisitorFunctions, o: Any
):
Expand Down Expand Up @@ -353,6 +359,10 @@ async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
await self._visit_coresdk_workflow_activation_ResolveNexusOperation(
fs, o.resolve_nexus_operation
)
elif o.HasField("resolve_stream_append"):
await self._visit_coresdk_workflow_activation_ResolveStreamAppend(
fs, o.resolve_stream_append
)

async def _visit_coresdk_workflow_activation_WorkflowActivation(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -492,6 +502,11 @@ async def _visit_coresdk_workflow_commands_ScheduleNexusOperation(
if o.HasField("input"):
await self._visit_nexus_operation_input_payload(fs, o.input)

async def _visit_coresdk_workflow_commands_AppendToStream(
self, fs: VisitorFunctions, o: Any
):
await self._visit_payload_container(fs, o.bodies)

async def _visit_coresdk_workflow_commands_WorkflowCommand(
self, fs: VisitorFunctions, o: Any
):
Expand Down Expand Up @@ -551,6 +566,10 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(
await self._visit_coresdk_workflow_commands_ScheduleNexusOperation(
fs, o.schedule_nexus_operation
)
elif o.HasField("append_to_stream"):
await self._visit_coresdk_workflow_commands_AppendToStream(
fs, o.append_to_stream
)

async def _visit_coresdk_workflow_completion_Success(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -639,6 +658,60 @@ async def _visit_temporal_api_notificationservice_v1_OnCompleteResponse(
) -> None:
pass

async def _visit_temporal_api_sdk_v1_CreateStreamRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_sdk_v1_CreateStreamResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_stream_v1_AppendRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_temporal_api_sdk_v1_AppendRecordsRequest(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_AppendRecord(fs, v)

async def _visit_temporal_api_streamservice_v1_AppendRecordsResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_sdk_v1_ReadRecordsRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_stream_v1_StreamRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_temporal_api_streamservice_v1_ReadRecordsResponse(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_StreamRecord(fs, v)

async def _visit_temporal_api_sdk_v1_DescribeStreamRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_streamservice_v1_DescribeStreamResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_common_v1_Header(self, fs: VisitorFunctions, o: Any):
for v in o.fields.values():
await self._visit_temporal_api_common_v1_Payload(fs, v)
Expand Down
33 changes: 18 additions & 15 deletions temporalio/bridge/proto/activity_result/activity_result_pb2.py

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

14 changes: 14 additions & 0 deletions temporalio/bridge/proto/activity_result/activity_result_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import google.protobuf.timestamp_pb2
import temporalio.api.common.v1.message_pb2
import temporalio.api.enums.v1.failed_cause_pb2
import temporalio.api.failure.v1.message_pb2
import temporalio.bridge.proto.common.common_pb2

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

Expand Down Expand Up @@ -253,6 +254,7 @@ class DoBackoff(google.protobuf.message.Message):
ATTEMPT_FIELD_NUMBER: builtins.int
BACKOFF_DURATION_FIELD_NUMBER: builtins.int
ORIGINAL_SCHEDULE_TIME_FIELD_NUMBER: builtins.int
LOCAL_ACTIVITY_ORIGIN_FIELD_NUMBER: builtins.int
attempt: builtins.int
"""The attempt number that lang should provide when scheduling the retry. If the LA failed
on attempt 4 and we told lang to back off with a timer, this number will be 5.
Expand All @@ -265,18 +267,28 @@ class DoBackoff(google.protobuf.message.Message):
to the retry LA.
"""

@property
def local_activity_origin(
self,
) -> temporalio.bridge.proto.common.common_pb2.LocalActivityOrigin:
"""Pass this origin to the retry so the timer cannot change its Producer identity."""

def __init__(
self,
*,
attempt: builtins.int = ...,
backoff_duration: google.protobuf.duration_pb2.Duration | None = ...,
original_schedule_time: google.protobuf.timestamp_pb2.Timestamp | None = ...,
local_activity_origin: temporalio.bridge.proto.common.common_pb2.LocalActivityOrigin
| None = ...,
) -> None: ...
def HasField(
self,
field_name: typing.Literal[
"backoff_duration",
b"backoff_duration",
"local_activity_origin",
b"local_activity_origin",
"original_schedule_time",
b"original_schedule_time",
],
Expand All @@ -288,6 +300,8 @@ class DoBackoff(google.protobuf.message.Message):
b"attempt",
"backoff_duration",
b"backoff_duration",
"local_activity_origin",
b"local_activity_origin",
"original_schedule_time",
b"original_schedule_time",
],
Expand Down
Loading
Loading