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
1 change: 1 addition & 0 deletions changelog/added/chatty-stream-otter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental Stream calls for clients and Activities, with client interceptors for each operation.
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
6 changes: 3 additions & 3 deletions temporalio/api/sdk/v1/task_complete_metadata_pb2.py

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

21 changes: 21 additions & 0 deletions temporalio/api/sdk/v1/task_complete_metadata_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WorkflowTaskCompletedMetadata(google.protobuf.message.Message):
LANG_USED_FLAGS_FIELD_NUMBER: builtins.int
SDK_NAME_FIELD_NUMBER: builtins.int
SDK_VERSION_FIELD_NUMBER: builtins.int
PENDING_LOCAL_ACTIVITY_SEQS_FIELD_NUMBER: builtins.int
sdk_name: builtins.str
"""Name of the SDK that processed the task. This is usually something like "temporal-go" and is
usually the same as client-name gRPC header. This should only be set if its value changed
Expand Down Expand Up @@ -71,13 +72,31 @@ class WorkflowTaskCompletedMetadata(google.protobuf.message.Message):
aip.dev/not-precedent: These really shouldn't have negative values. --)
"""

@property
def pending_local_activity_seqs(
self,
) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.int]:
"""Sequence numbers of the local activities that this workflow task scheduled and that had no
result when the task completed. Set only in that case. On replay, the SDK gives each of these
local activities the origin that it had when this task scheduled it, so all its attempts keep
the same origin. The origin uses the `started_event_id` of the workflow task completion before
this one, so this field doesn't repeat it.

Experimental. Might change in the future.

(-- api-linter: core::0141::forbidden-types=disabled
aip.dev/not-precedent: Sequence numbers are never negative. --)
"""

def __init__(
self,
*,
core_used_flags: collections.abc.Iterable[builtins.int] | None = ...,
lang_used_flags: collections.abc.Iterable[builtins.int] | None = ...,
sdk_name: builtins.str = ...,
sdk_version: builtins.str = ...,
pending_local_activity_seqs: collections.abc.Iterable[builtins.int]
| None = ...,
) -> None: ...
def ClearField(
self,
Expand All @@ -86,6 +105,8 @@ class WorkflowTaskCompletedMetadata(google.protobuf.message.Message):
b"core_used_flags",
"lang_used_flags",
b"lang_used_flags",
"pending_local_activity_seqs",
b"pending_local_activity_seqs",
"sdk_name",
b"sdk_name",
"sdk_version",
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.

16 changes: 16 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,30 @@ class DoBackoff(google.protobuf.message.Message):
to the retry LA.
"""

@property
def local_activity_origin(
self,
) -> temporalio.bridge.proto.common.common_pb2.LocalActivityOrigin:
"""The origin of this local activity. Lang must pass it to the retry that it schedules after
the backoff, so all attempts keep the same origin.
"""

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 +302,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