-
Notifications
You must be signed in to change notification settings - Fork 105
Nexus: worker, workflow-backed operations, and workflow caller #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b34a17
99de490
7bca8e6
3344fee
222dd9d
590af44
8d61f18
051ea8d
48a9a79
2a1e5a5
eba55cc
b9799cb
943222e
2224b8a
0626da7
220d0a4
61ded24
dcda5a5
be1ad3f
93e19f6
24db857
49721fa
903c3ae
9e0f8a6
a08b77e
5d742c1
9dbe4a1
5532a14
900987f
70fafc1
823c17e
f617827
679f8ba
9c7fee9
d35f9e4
876a3df
0541f50
d25ba2f
c8a110c
6e3f0b5
aeab540
643f1fe
1185e30
507f233
a766e67
f060c79
60a21ca
5ffa77c
fb8f22c
971a31f
625bec7
7826bce
91d122b
9b3c0bf
d82f36f
cf5d3be
7f6b8b8
021e733
ef0181b
62dda51
50c076c
c8d2992
6c31692
28e5ae2
621ddb0
4c99839
09f6837
a5bb59a
82785f7
15f5c09
5d9ffc9
96c4b90
ee9c376
b52fb56
8504503
3704cc8
f3245fe
0d2f915
36190e7
bc068b4
0806af4
e287e9a
a56e332
9c7bc6d
85052a8
7c279aa
408f1b9
f3966ea
fd76792
ad33f8f
d76b08f
1ad78bb
98385fb
366e00f
df828de
0637897
9d3c2ab
184511d
3d17ba7
cc96faf
3c94752
201785d
150e39d
7866b01
aac8571
691a18d
f51e9be
351e60e
fa5a2c8
c766235
f34d337
1e3cdca
7ad0d0c
6c84511
8a88b4f
e3d75b0
39abf89
9b4f714
fb2f232
2b2583a
26118a6
cf396b7
a7094de
3d1979c
133a395
789cf4d
1761374
9e1bef9
0b3ecd8
b920bb8
051f8e5
688baf8
09ae187
67a6437
10fe421
07f3463
52ee7cf
f1a5702
25d9a12
5fc7d6c
23a7260
4326d3a
8c9d2f7
172744e
b508b6c
ef157ad
665d9a1
912dc23
426db10
81b810a
0645434
9bb49c2
2713bbd
f2dcb45
13b7818
8f8e213
0b028b6
3aa03d8
44aa00f
b863610
6e16689
ec3554b
3f526c9
fece846
d76e859
2843357
60222c6
9a74493
f3a296f
5b9021f
36b87e4
699275d
df84d4c
b51dace
3e0cc97
c07bf53
7facb2c
3376420
4bf4473
dc95ae1
49b8e29
df68927
627344e
cf99e9a
59470c1
d19d781
c87038b
8f31739
b288dc3
05b2eb1
220e1b8
7e7c37c
16d57ae
eee2438
30a4c07
163ae07
3f8bb02
be6c623
c03fbcb
0b895e8
3627b3f
a4890c7
965ce79
1f6cfd9
f084e66
c6667db
a8fdc3f
5a562ee
29e2b2d
7c77425
2e366ba
6046dd9
051c9bb
0dbd94b
ef48e75
d42b3f6
3143860
476a1c1
fa5af60
352e8a0
6a3071b
fe2a6de
9934c5e
d66df7a
2fabfa1
c1f7661
90a2449
d5e9f88
07ca831
9189a16
c967aa5
43660f4
399c1ec
12f98a1
b6e084d
63c21fe
9afd28f
3ea025d
c00dbab
12071e0
98d561d
c073963
d5864fe
3783ac5
f744680
aa3aa23
57eee56
eae3197
917873c
02a1ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,9 +464,17 @@ async def start_workflow( | |
rpc_metadata: Mapping[str, str] = {}, | ||
rpc_timeout: Optional[timedelta] = None, | ||
request_eager_start: bool = False, | ||
stack_level: int = 2, | ||
priority: temporalio.common.Priority = temporalio.common.Priority.default, | ||
versioning_override: Optional[temporalio.common.VersioningOverride] = None, | ||
# The following options should not be considered part of the public API. They | ||
# are deliberately not exposed in overloads, and are not subject to any | ||
# backwards compatibility guarantees. | ||
callbacks: Sequence[Callback] = [], | ||
workflow_event_links: Sequence[ | ||
temporalio.api.common.v1.Link.WorkflowEvent | ||
] = [], | ||
request_id: Optional[str] = None, | ||
stack_level: int = 2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are also missing the conflict options which are required for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would for now throw if a user tries to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: if (
id_conflict_policy
== temporalio.common.WorkflowIDConflictPolicy.USE_EXISTING
):
raise RuntimeError(
"WorkflowIDConflictPolicy.USE_EXISTING is not yet supported when starting a workflow "
"that backs a Nexus operation (Python SDK Nexus support is at Pre-release stage)."
) |
||
) -> WorkflowHandle[Any, Any]: | ||
"""Start a workflow and return its handle. | ||
|
||
|
@@ -529,7 +537,6 @@ async def start_workflow( | |
name, result_type_from_type_hint = ( | ||
temporalio.workflow._Definition.get_name_and_result_type(workflow) | ||
) | ||
|
||
return await self._impl.start_workflow( | ||
StartWorkflowInput( | ||
workflow=name, | ||
|
@@ -557,6 +564,9 @@ async def start_workflow( | |
rpc_timeout=rpc_timeout, | ||
request_eager_start=request_eager_start, | ||
priority=priority, | ||
callbacks=callbacks, | ||
workflow_event_links=workflow_event_links, | ||
request_id=request_id, | ||
) | ||
) | ||
|
||
|
@@ -5193,6 +5203,10 @@ class StartWorkflowInput: | |
rpc_timeout: Optional[timedelta] | ||
request_eager_start: bool | ||
priority: temporalio.common.Priority | ||
# The following options are experimental and unstable. | ||
callbacks: Sequence[Callback] | ||
workflow_event_links: Sequence[temporalio.api.common.v1.Link.WorkflowEvent] | ||
request_id: Optional[str] | ||
versioning_override: Optional[temporalio.common.VersioningOverride] = None | ||
|
||
|
||
|
@@ -5807,8 +5821,30 @@ async def _build_start_workflow_execution_request( | |
self, input: StartWorkflowInput | ||
) -> temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest: | ||
req = temporalio.api.workflowservice.v1.StartWorkflowExecutionRequest() | ||
req.request_eager_execution = input.request_eager_start | ||
await self._populate_start_workflow_execution_request(req, input) | ||
# _populate_start_workflow_execution_request is used for both StartWorkflowInput | ||
# and UpdateWithStartStartWorkflowInput. UpdateWithStartStartWorkflowInput does | ||
# not have the following two fields so they are handled here. | ||
req.request_eager_execution = input.request_eager_start | ||
if input.request_id: | ||
req.request_id = input.request_id | ||
|
||
links = [ | ||
temporalio.api.common.v1.Link(workflow_event=link) | ||
for link in input.workflow_event_links | ||
] | ||
req.completion_callbacks.extend( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put the links on the callbacks so they can be associated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
temporalio.api.common.v1.Callback( | ||
nexus=temporalio.api.common.v1.Callback.Nexus( | ||
url=callback.url, | ||
header=callback.headers, | ||
), | ||
links=links, | ||
) | ||
for callback in input.callbacks | ||
) | ||
# Links are duplicated on request for compatibility with older server versions. | ||
req.links.extend(links) | ||
return req | ||
|
||
async def _build_signal_with_start_workflow_execution_request( | ||
|
@@ -7231,6 +7267,25 @@ def api_key(self, value: Optional[str]) -> None: | |
self.service_client.update_api_key(value) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class NexusCallback: | ||
"""Nexus callback to attach to events such as workflow completion. | ||
|
||
.. warning:: | ||
This API is experimental and unstable. | ||
""" | ||
|
||
url: str | ||
"""Callback URL.""" | ||
|
||
headers: Mapping[str, str] | ||
"""Header to attach to callback request.""" | ||
|
||
|
||
# Intended to become a union of callback types | ||
Callback = NexusCallback | ||
Comment on lines
+7285
to
+7286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we wait until there is need for a union? It's easy to build a union at that time, but for now, a single-value alias seems unnecessary API surface. (pedantic and unimportant, non-blocking) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes the types clearer in |
||
|
||
|
||
async def _encode_user_metadata( | ||
converter: temporalio.converter.DataConverter, | ||
summary: Optional[Union[str, temporalio.api.common.v1.Payload]], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see this section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump, we should add this section showing how to make simple Nexus Python operation and how to call Nexus operations from workflows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add README docs shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nexus README content exists now