Skip to content
Closed
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
5 changes: 5 additions & 0 deletions changelog/added/steady-stream-heron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Add experimental `temporalio.client.StreamStore`, the base class of a Stream Store, and `temporalio.testing.MemoryStreamStore`, a Store that keeps its Streams in memory for tests and local runs.
Add experimental Streams for client and Activity code. `stream_config=StreamConfig(stores=[...])` of `Client.connect` gives a client its Stream Stores, and `Client.create_stream` and `Client.get_stream` return a `Stream` to append to, read, describe and close. A failed call raises `temporalio.exceptions.StreamError` with a `reason`. A read of a Stream from `get_stream` needs `body_type=` or a `StreamRef` with a type argument, and raises `TypeError` with neither. `temporalio.contrib.streams.current_producer` gives the Producer of an Activity attempt, and `as_producer` gives back one that code stored.
Add experimental Streams for Workflow code. `workflow.create_stream` and `workflow.get_stream` return a `Stream` to append to, describe and close on the Stream Stores of the Worker's client, and `Replayer(stream_config=...)` gives a replay its Stores.
Add experimental Stream reads for Workflow code. `Stream.read`, `read_pages` and `read_page` of a Workflow `Stream` give the Records as they come, a replay reads them again from the Store, and `temporalio.workflow.StreamReplayError` in the failure exception types of a Worker or a Workflow fails the Workflow when the Store no longer has them. The Worker option `stream_read_max_wait` bounds the wait of one Store call of a read.
Add experimental `temporalio.contrib.streams.BufferedAppender`, which batches the appends of one Stream in client and Activity code. `append` returns immediately, a batch waits at most `max_delay`, one write runs at a time, and `async with` or `flush()` writes what is left.
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
79 changes: 76 additions & 3 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 @@ -72,6 +72,7 @@ temporalio-sdk-core = { version = "0.11.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 ClientTlsConfig.verification_server_name.
Expand Down
59 changes: 53 additions & 6 deletions temporalio/bridge/_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,38 @@ async def _visit_coresdk_workflow_activation_ResolveNexusOperation(
if o.HasField("result"):
await self._visit_coresdk_nexus_NexusOperationResult(fs, o.result)

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_coresdk_workflow_activation_StreamPage(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_StreamRecord(fs, v)

async def _visit_coresdk_workflow_activation_ResolveStreamRead(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("page"):
await self._visit_coresdk_workflow_activation_StreamPage(fs, o.page)
elif o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

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_ResolveStreamClose(
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 +385,18 @@ async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
await self._visit_coresdk_workflow_activation_ResolveNexusOperation(
fs, o.resolve_nexus_operation
)
elif o.HasField("resolve_stream_read"):
await self._visit_coresdk_workflow_activation_ResolveStreamRead(
fs, o.resolve_stream_read
)
elif o.HasField("resolve_stream_append"):
await self._visit_coresdk_workflow_activation_ResolveStreamAppend(
fs, o.resolve_stream_append
)
elif o.HasField("resolve_stream_close"):
await self._visit_coresdk_workflow_activation_ResolveStreamClose(
fs, o.resolve_stream_close
)

async def _visit_coresdk_workflow_activation_WorkflowActivation(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -492,6 +536,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 +600,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 @@ -681,12 +734,6 @@ async def _visit_temporal_api_streamservice_v1_ReadRecordsRequest(
) -> 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
):
Expand Down
19 changes: 18 additions & 1 deletion temporalio/bridge/proto/external_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
from .external_data_pb2 import LocalActivityMarkerData, PatchedMarkerData
from .external_data_pb2 import (
LocalActivityMarkerData,
PatchedMarkerData,
StreamAppendOffsets,
StreamAppendResult,
StreamCloseIntent,
StreamCloseResult,
StreamMarkerData,
StreamReadPage,
StreamReadResult,
)

__all__ = [
"LocalActivityMarkerData",
"PatchedMarkerData",
"StreamAppendOffsets",
"StreamAppendResult",
"StreamCloseIntent",
"StreamCloseResult",
"StreamMarkerData",
"StreamReadPage",
"StreamReadResult",
]
Loading