56
56
import temporalio .converter
57
57
import temporalio .exceptions
58
58
import temporalio .workflow
59
- from temporalio import workflow
60
59
61
60
from .types import (
62
61
AnyType ,
@@ -751,15 +750,15 @@ def workflow_start_local_activity(
751
750
) -> ActivityHandle [Any ]: ...
752
751
753
752
@abstractmethod
754
- def workflow_start_nexus_operation (
753
+ async def workflow_start_nexus_operation (
755
754
self ,
756
755
endpoint : str ,
757
756
service : str ,
758
757
operation : str ,
759
758
input : Any ,
760
759
schedule_to_close_timeout : Optional [timedelta ] = None ,
761
760
headers : Optional [Mapping [str , str ]] = None ,
762
- ) -> asyncio . Task : ...
761
+ ) -> NexusOperationHandle [ Any ] : ...
763
762
764
763
@abstractmethod
765
764
def workflow_time_ns (self ) -> int : ...
@@ -4250,21 +4249,43 @@ async def execute_child_workflow(
4250
4249
O = TypeVar ("O" )
4251
4250
4252
4251
4252
+ class NexusOperationHandle (Generic [O ]):
4253
+ async def result (self ) -> O :
4254
+ raise NotImplementedError
4255
+
4256
+
4253
4257
async def start_nexus_operation (
4254
4258
endpoint : str ,
4255
4259
service : str ,
4256
4260
operation : str ,
4257
4261
input : Any ,
4262
+ * ,
4258
4263
schedule_to_close_timeout : Optional [timedelta ] = None ,
4259
4264
headers : Optional [Mapping [str , str ]] = None ,
4260
- ) -> asyncio .Task :
4265
+ ) -> NexusOperationHandle [Any ]:
4266
+ """Start a Nexus operation and return its handle.
4267
+
4268
+ Args:
4269
+ endpoint: The Nexus endpoint.
4270
+ service: The Nexus service.
4271
+ operation: The Nexus operation.
4272
+ input: The Nexus operation input.
4273
+ schedule_to_close_timeout: Timeout for the entire operation attempt.
4274
+ headers: Headers to send with the Nexus HTTP request.
4275
+
4276
+ Returns:
4277
+ A handle to the Nexus operation. The result can be obtained as
4278
+ ```python
4279
+ await handle.result()
4280
+ ```
4281
+ """
4261
4282
return await _Runtime .current ().workflow_start_nexus_operation (
4262
- endpoint ,
4263
- service ,
4264
- operation ,
4265
- input ,
4266
- schedule_to_close_timeout ,
4267
- headers ,
4283
+ endpoint = endpoint ,
4284
+ service = service ,
4285
+ operation = operation ,
4286
+ input = input ,
4287
+ schedule_to_close_timeout = schedule_to_close_timeout ,
4288
+ headers = headers ,
4268
4289
)
4269
4290
4270
4291
@@ -5029,7 +5050,7 @@ async def method(
5029
5050
schedule_to_close_timeout : Optional [timedelta ] = None ,
5030
5051
headers : Optional [Mapping [str , str ]] = None ,
5031
5052
):
5032
- return await workflow .start_nexus_operation (
5053
+ return await temporalio . workflow .start_nexus_operation (
5033
5054
endpoint = endpoint ,
5034
5055
service = interface .__name__ ,
5035
5056
operation = name ,
@@ -5042,15 +5063,15 @@ async def method(
5042
5063
5043
5064
methods [name ] = method
5044
5065
5045
- class StartOperation :
5066
+ class _ServiceClient :
5046
5067
async def start_operation (
5047
5068
self ,
5048
5069
operation : Callable [[Any , I ], Awaitable [O ]],
5049
5070
input : I ,
5050
5071
schedule_to_close_timeout : Optional [timedelta ] = None ,
5051
5072
headers : Optional [Mapping [str , str ]] = None ,
5052
- ) -> asyncio . Task [O ]:
5053
- return await workflow .start_nexus_operation (
5073
+ ) -> NexusOperationHandle [O ]:
5074
+ return await temporalio . workflow .start_nexus_operation (
5054
5075
endpoint = endpoint ,
5055
5076
service = interface .__name__ ,
5056
5077
operation = operation .__name__ ,
@@ -5061,7 +5082,7 @@ async def start_operation(
5061
5082
headers = headers or {},
5062
5083
)
5063
5084
5064
- cls = type (f"{ interface .__name__ } Client" , (StartOperation ,), methods )
5085
+ cls = type (f"{ interface .__name__ } Client" , (_ServiceClient ,), methods )
5065
5086
return cls () # type: ignore
5066
5087
5067
5088
@@ -5082,8 +5103,8 @@ async def start_operation(
5082
5103
input : I ,
5083
5104
schedule_to_close_timeout : Optional [timedelta ] = None ,
5084
5105
headers : Optional [Mapping [str , str ]] = None ,
5085
- ) -> asyncio . Task [O ]:
5086
- return await workflow .start_nexus_operation (
5106
+ ) -> NexusOperationHandle [O ]:
5107
+ return await temporalio . workflow .start_nexus_operation (
5087
5108
endpoint = self ._endpoint ,
5088
5109
service = self ._service_name ,
5089
5110
operation = operation .name ,
@@ -5104,5 +5125,4 @@ async def execute_operation(
5104
5125
handle = await self .start_operation (
5105
5126
operation , input , schedule_to_close_timeout , headers
5106
5127
)
5107
- # TODO(dan): handle.result()
5108
- return await handle
5128
+ return await handle .result ()
0 commit comments