-
Notifications
You must be signed in to change notification settings - Fork 206
NEXUS-484: Support UpdateWorkflow as a Nexus Operation #1631
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
Draft
mavemuri
wants to merge
1
commit into
main
Choose a base branch
from
mavemuri/update-nexus-op
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,15 +15,17 @@ | |
| overload, | ||
| ) | ||
|
|
||
| from nexusrpc import HandlerError, HandlerErrorType | ||
| from nexusrpc import HandlerError, HandlerErrorType, OperationError, OperationErrorState | ||
| from nexusrpc.handler import StartOperationResultAsync, StartOperationResultSync | ||
| from typing_extensions import Self | ||
|
|
||
| import temporalio.common | ||
| from temporalio.nexus._operation_context import ( | ||
| _start_nexus_backed_workflow_update, | ||
| _start_nexus_backing_workflow, | ||
| _TemporalStartOperationContext, | ||
| ) | ||
| from temporalio.nexus._token import UpdateHandle | ||
| from temporalio.types import ( | ||
| MethodAsyncNoParam, | ||
| MethodAsyncSingleParam, | ||
|
|
@@ -35,6 +37,7 @@ | |
|
|
||
| if TYPE_CHECKING: | ||
| import temporalio.client | ||
| import temporalio.workflow | ||
|
|
||
|
|
||
| _ResultT = TypeVar("_ResultT") | ||
|
|
@@ -279,6 +282,85 @@ async def start_workflow( | |
| """ | ||
| ... | ||
|
|
||
| # Overload for no-param update | ||
| @overload | ||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: temporalio.workflow.UpdateMethodMultiParam[[Any], ReturnType], | ||
| *, | ||
| id: str | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| ) -> TemporalOperationResult[ReturnType]: ... | ||
|
|
||
| # Overload for single-param update | ||
| @overload | ||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: temporalio.workflow.UpdateMethodMultiParam[ | ||
| [Any, ParamType], ReturnType | ||
| ], | ||
| arg: ParamType, | ||
| *, | ||
| id: str | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| ) -> TemporalOperationResult[ReturnType]: ... | ||
|
|
||
| # Overload for multi-param update | ||
| @overload | ||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: temporalio.workflow.UpdateMethodMultiParam[MultiParamSpec, ReturnType], | ||
| *, | ||
| args: MultiParamSpec.args, # type: ignore | ||
| id: str | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| ) -> TemporalOperationResult[ReturnType]: ... | ||
|
|
||
| # Overload for string-name update | ||
| @overload | ||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: str, | ||
| arg: Any = temporalio.common._arg_unset, | ||
| *, | ||
| args: Sequence[Any] = [], | ||
| id: str | None = None, | ||
| result_type: type[ReturnType] | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| ) -> TemporalOperationResult[ReturnType]: ... | ||
|
|
||
| # draft-review: check why run_id and first_execution_run_id are not used | ||
| # for update workflow in python sdk | ||
| @abstractmethod | ||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: str | Callable, | ||
| arg: Any = temporalio.common._arg_unset, | ||
| *, | ||
| args: Sequence[Any] = [], | ||
| id: str | None = None, | ||
| result_type: type | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| # run_id: str | None = None, | ||
| # first_execution_run_id: str | None = None, | ||
| ) -> TemporalOperationResult[Any]: | ||
| """Start a workflow update as the backing asynchronous Nexus operation. | ||
|
|
||
| .. warning:: | ||
| This API is experimental and unstable. | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| class _TemporalNexusClient(TemporalNexusClient): # pyright: ignore[reportUnusedClass] | ||
| """Nexus-aware wrapper around a Temporal Client. | ||
|
|
@@ -377,3 +459,52 @@ async def start_workflow( | |
| ) | ||
|
|
||
| return TemporalOperationResult.async_token(wf_handle.to_token()) | ||
|
|
||
| async def start_workflow_update( | ||
| self, | ||
| workflow_id: str, | ||
| update: str | Callable, | ||
| arg: Any = temporalio.common._arg_unset, | ||
| *, | ||
| args: Sequence[Any] = [], | ||
| id: str | None = None, | ||
| result_type: type | None = None, | ||
| rpc_metadata: Mapping[str, str | bytes] = {}, | ||
| rpc_timeout: timedelta | None = None, | ||
| # run_id: str | None = None, | ||
|
Contributor
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. Why are these commented out |
||
| # first_execution_run_id: str | None = None, | ||
| ) -> TemporalOperationResult[Any]: | ||
| """Start a workflow update as the backing asynchronous Nexus operation.""" | ||
| if not self._temporal_context.nexus_context.callback_url: | ||
| raise HandlerError( | ||
| "callback URL is required for a workflow update Nexus operation", | ||
| type=HandlerErrorType.BAD_REQUEST, | ||
| ) | ||
| with self._reserve_async_start(): | ||
| update_handle = await _start_nexus_backed_workflow_update( | ||
| temporal_context=self._temporal_context, | ||
| workflow_id=workflow_id, | ||
| update=update, | ||
| arg=arg, | ||
| args=args, | ||
| id=id, | ||
| result_type=result_type, | ||
| rpc_metadata=rpc_metadata, | ||
| rpc_timeout=rpc_timeout, | ||
| # run_id=run_id, | ||
| # first_execution_run_id=first_execution_run_id, | ||
| ) | ||
| # If the update has already completed, return the result synchronously | ||
| # This is in-line with the Go implementation as well | ||
| if update_handle._known_outcome is not None: | ||
| try: | ||
| result = await update_handle.result() | ||
| except temporalio.client.WorkflowUpdateFailedError as err: | ||
| raise OperationError( | ||
| str(err), state=OperationErrorState.FAILED | ||
| ) from err | ||
| return TemporalOperationResult.sync(result) | ||
| nexus_handle: UpdateHandle[Any] = ( | ||
| UpdateHandle._unsafe_from_client_workflow_update_handle(update_handle) | ||
| ) | ||
| return TemporalOperationResult.async_token(nexus_handle.to_token()) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing run ID