File tree Expand file tree Collapse file tree 4 files changed +26
-10
lines changed Expand file tree Collapse file tree 4 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 17
17
)
18
18
19
19
from temporalio .nexus ._operation_context import (
20
- TemporalStartOperationContext ,
21
20
WorkflowRunOperationContext ,
22
21
)
23
22
from temporalio .nexus ._operation_handlers import (
@@ -115,8 +114,11 @@ def operation_handler_factory(
115
114
async def _start (
116
115
ctx : StartOperationContext , input : InputT
117
116
) -> WorkflowHandle [OutputT ]:
118
- tctx = TemporalStartOperationContext .get ()
119
- return await start (self , WorkflowRunOperationContext (tctx ), input )
117
+ return await start (
118
+ self ,
119
+ WorkflowRunOperationContext .from_start_operation_context (ctx ),
120
+ input ,
121
+ )
120
122
121
123
_start .__doc__ = start .__doc__
122
124
return WorkflowRunOperationHandler (_start , input_type , output_type )
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
+ import dataclasses
3
4
import logging
4
5
import re
5
6
import urllib .parse
@@ -168,17 +169,28 @@ def add_outbound_links(
168
169
return workflow_handle
169
170
170
171
171
- @dataclass
172
- class WorkflowRunOperationContext :
173
- temporal_context : TemporalStartOperationContext
172
+ @dataclass (frozen = True )
173
+ class WorkflowRunOperationContext (StartOperationContext ):
174
+ _temporal_context : Optional [TemporalStartOperationContext ] = None
175
+
176
+ @property
177
+ def temporal_context (self ) -> TemporalStartOperationContext :
178
+ if not self ._temporal_context :
179
+ raise RuntimeError ("Temporal context not set" )
180
+ return self ._temporal_context
174
181
175
182
@property
176
183
def nexus_context (self ) -> StartOperationContext :
177
184
return self .temporal_context .nexus_context
178
185
179
186
@classmethod
180
- def get (cls ) -> WorkflowRunOperationContext :
181
- return cls (TemporalStartOperationContext .get ())
187
+ def from_start_operation_context (
188
+ cls , ctx : StartOperationContext
189
+ ) -> WorkflowRunOperationContext :
190
+ return cls (
191
+ _temporal_context = TemporalStartOperationContext .get (),
192
+ ** {f .name : getattr (ctx , f .name ) for f in dataclasses .fields (ctx )},
193
+ )
182
194
183
195
# Overload for single-param workflow
184
196
# TODO(nexus-prerelease): bring over other overloads
Original file line number Diff line number Diff line change @@ -160,7 +160,8 @@ async def start(
160
160
# TODO(nexus-preview): what do we want the DX to be for a user who is
161
161
# starting a Nexus backing workflow from a custom start method? (They may
162
162
# need to do this in order to customize the cancel method).
163
- handle = await WorkflowRunOperationContext .get ().start_workflow (
163
+ tctx = WorkflowRunOperationContext .from_start_operation_context (ctx )
164
+ handle = await tctx .start_workflow (
164
165
HandlerWorkflow .run ,
165
166
HandlerWfInput (op_input = input ),
166
167
id = input .response_type .operation_workflow_id ,
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ def __init__(self):
49
49
async def start (
50
50
self , ctx : StartOperationContext , input : Input
51
51
) -> StartOperationResultAsync :
52
- handle = await WorkflowRunOperationContext .get ().start_workflow (
52
+ tctx = WorkflowRunOperationContext .from_start_operation_context (ctx )
53
+ handle = await tctx .start_workflow (
53
54
EchoWorkflow .run ,
54
55
input .value ,
55
56
id = str (uuid .uuid4 ()),
You can’t perform that action at this time.
0 commit comments