11from datetime import timedelta
22
3- import xray
43from temporalio import workflow
54from temporalio .exceptions import FailureError
65from temporalio .workflow import NexusClient
@@ -25,7 +24,6 @@ def __init__(self):
2524
2625@workflow .defn
2726class EchoCallerWorkflow (CallerWorkflowBase ):
28- @xray .start_as_current_workflow_method_span ()
2927 @workflow .run
3028 async def run (self , message : str ) -> EchoOutput :
3129 op_output = await self .nexus_client .execute_operation (
@@ -37,7 +35,6 @@ async def run(self, message: str) -> EchoOutput:
3735
3836@workflow .defn
3937class Echo2CallerWorkflow (CallerWorkflowBase ):
40- @xray .start_as_current_workflow_method_span ()
4138 @workflow .run
4239 async def run (self , message : str ) -> EchoOutput :
4340 op_output = await self .nexus_client .execute_operation (
@@ -49,7 +46,6 @@ async def run(self, message: str) -> EchoOutput:
4946
5047@workflow .defn
5148class Echo3CallerWorkflow (CallerWorkflowBase ):
52- @xray .start_as_current_workflow_method_span ()
5349 @workflow .run
5450 async def run (self , message : str ) -> EchoOutput :
5551 op_output = await self .nexus_client .execute_operation (
@@ -61,7 +57,6 @@ async def run(self, message: str) -> EchoOutput:
6157
6258@workflow .defn
6359class HelloCallerWorkflow (CallerWorkflowBase ):
64- @xray .start_as_current_workflow_method_span ()
6560 @workflow .run
6661 async def run (self , name : str ) -> HelloOutput :
6762 # TODO: Java returns a handle immediately. The handle has a blocking method to
@@ -71,36 +66,24 @@ async def run(self, name: str) -> HelloOutput:
7166 MyNexusService .hello ,
7267 HelloInput (name ),
7368 )
74- span = xray .get_current_span ()
75- span .add_event ("Got NexusOperationHandle (1)" )
7669 assert handle .cancel ()
7770 try :
7871 await handle
7972 # TODO(dan): But should this be asyncio.CancelledError? (there's also
8073 # temporalio.exceptions.CancelledError which doesn't inherit from
8174 # asyncio.CancelledError; as a workflow author, this confused me)
82- except FailureError as e :
83- span .add_event (
84- "Caught error, retrying operation" ,
85- attributes = {
86- "type" : e .__class__ .__name__ ,
87- "message" : str (e ),
88- },
89- )
75+ except FailureError :
9076 handle = await self .nexus_client .start_operation (
9177 MyNexusService .hello ,
9278 HelloInput (name ),
9379 )
94- span .add_event ("Got NexusOperationHandle (2)" )
9580 result = await handle
96- span .add_event (f"Got result (2): { result } " )
9781 return result
9882 raise AssertionError ("Expected Nexus operation to be cancelled" )
9983
10084
10185@workflow .defn
10286class Hello2CallerWorkflow (CallerWorkflowBase ):
103- @xray .start_as_current_workflow_method_span ()
10487 @workflow .run
10588 async def run (self , name : str ) -> HelloOutput :
10689 handle = await self .nexus_client .start_operation (
@@ -112,7 +95,6 @@ async def run(self, name: str) -> HelloOutput:
11295
11396@workflow .defn
11497class Hello3CallerWorkflow (CallerWorkflowBase ):
115- @xray .start_as_current_workflow_method_span ()
11698 @workflow .run
11799 async def run (self , name : str ) -> HelloOutput :
118100 handle = await self .nexus_client .start_operation (
0 commit comments