-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathworkflows.py
100 lines (84 loc) · 2.87 KB
/
workflows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from datetime import timedelta
import xray
from temporalio import workflow
from temporalio.workflow import NexusClient
from nexus.service.interface import (
EchoInput,
EchoOutput,
HelloInput,
HelloOutput,
MyNexusService,
)
class CallerWorkflowBase:
def __init__(self):
self.nexus_client = NexusClient(
MyNexusService, # or string name "my-nexus-service",
"my-nexus-endpoint-name",
schedule_to_close_timeout=timedelta(seconds=30),
)
@workflow.defn
class EchoCallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, message: str) -> EchoOutput:
op_output = await self.nexus_client.execute_operation(
MyNexusService.echo,
EchoInput(message),
)
return op_output
@workflow.defn
class Echo2CallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, message: str) -> EchoOutput:
op_output = await self.nexus_client.execute_operation(
MyNexusService.echo2,
EchoInput(message),
)
return op_output
@workflow.defn
class Echo3CallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, message: str) -> EchoOutput:
op_output = await self.nexus_client.execute_operation(
MyNexusService.echo3,
EchoInput(message),
)
return op_output
@workflow.defn
class HelloCallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, name: str) -> HelloOutput:
# TODO: Java returns a handle immediately. The handle has a blocking method to
# wait until the operation has started (i.e. initial Nexus RPC response is
# available, so operation ID is available in the case of an async operation).
handle = await self.nexus_client.start_operation(
MyNexusService.hello,
HelloInput(name),
)
op_output = await handle
return op_output
@workflow.defn
class Hello2CallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, name: str) -> HelloOutput:
handle = await self.nexus_client.start_operation(
MyNexusService.hello2,
HelloInput(name),
)
op_output = await handle
return op_output
@workflow.defn
class Hello3CallerWorkflow(CallerWorkflowBase):
@xray.start_as_current_workflow_method_span()
@workflow.run
async def run(self, name: str) -> HelloOutput:
handle = await self.nexus_client.start_operation(
MyNexusService.hello3,
HelloInput(name),
)
op_output = await handle
return op_output