-
Notifications
You must be signed in to change notification settings - Fork 208
Add Temporal Nexus Operation Handler #2842
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
Open
Quinn-With-Two-Ns
wants to merge
6
commits into
temporalio:master
Choose a base branch
from
Quinn-With-Two-Ns:temporal-nexus-operation-handler
base: master
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5863dba
Add Temporal Nexus Operation Handler
Quinn-With-Two-Ns 6641b14
Update
Quinn-With-Two-Ns 05a2002
Update some docs
Quinn-With-Two-Ns acfa2e8
Update calling convention
Quinn-With-Two-Ns d1cd542
Code review
Quinn-With-Two-Ns ee62ae7
Address feedback
Quinn-With-Two-Ns 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
81 changes: 81 additions & 0 deletions
81
temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusStartWorkflowHelper.java
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package io.temporal.internal.nexus; | ||
|
|
||
| import static io.temporal.internal.common.LinkConverter.workflowEventToNexusLink; | ||
| import static io.temporal.internal.common.NexusUtil.nexusProtoLinkToLink; | ||
|
|
||
| import io.nexusrpc.handler.HandlerException; | ||
| import io.nexusrpc.handler.OperationContext; | ||
| import io.nexusrpc.handler.OperationStartDetails; | ||
| import io.temporal.api.common.v1.Link; | ||
| import io.temporal.api.common.v1.WorkflowExecution; | ||
| import io.temporal.api.enums.v1.EventType; | ||
| import io.temporal.internal.client.NexusStartWorkflowRequest; | ||
| import io.temporal.internal.client.NexusStartWorkflowResponse; | ||
| import java.net.URISyntaxException; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Shared helper for starting a workflow from a Nexus operation and attaching workflow links to the | ||
| * operation context. Used by both {@code WorkflowRunOperationImpl} and {@code | ||
| * TemporalNexusClientImpl}. | ||
| */ | ||
| public class NexusStartWorkflowHelper { | ||
|
|
||
| /** | ||
| * Starts a workflow via the provided invoker function, attaches workflow links to the operation | ||
| * context, and returns the response. | ||
| * | ||
| * @param ctx the operation context (links will be attached as a side-effect) | ||
| * @param details the operation start details containing requestId, callback, links | ||
| * @param invoker function that starts the workflow given a {@link NexusStartWorkflowRequest} | ||
| * @return the {@link NexusStartWorkflowResponse} containing the operation token and workflow | ||
| * execution | ||
| */ | ||
| public static NexusStartWorkflowResponse startWorkflowAndAttachLinks( | ||
| OperationContext ctx, | ||
| OperationStartDetails details, | ||
| Function<NexusStartWorkflowRequest, NexusStartWorkflowResponse> invoker) { | ||
| InternalNexusOperationContext nexusCtx = CurrentNexusOperationContext.get(); | ||
|
|
||
| NexusStartWorkflowRequest nexusRequest = | ||
| new NexusStartWorkflowRequest( | ||
| details.getRequestId(), | ||
| details.getCallbackUrl(), | ||
| details.getCallbackHeaders(), | ||
| nexusCtx.getTaskQueue(), | ||
| details.getLinks()); | ||
|
|
||
| NexusStartWorkflowResponse response = invoker.apply(nexusRequest); | ||
| WorkflowExecution workflowExec = response.getWorkflowExecution(); | ||
|
|
||
| // If the start workflow response returned a link use it, otherwise | ||
| // create the link information about the new workflow and return to the caller. | ||
| Link.WorkflowEvent workflowEventLink = | ||
| nexusCtx.getStartWorkflowResponseLink().hasWorkflowEvent() | ||
| ? nexusCtx.getStartWorkflowResponseLink().getWorkflowEvent() | ||
| : null; | ||
| if (workflowEventLink == null) { | ||
| workflowEventLink = | ||
| Link.WorkflowEvent.newBuilder() | ||
| .setNamespace(nexusCtx.getNamespace()) | ||
| .setWorkflowId(workflowExec.getWorkflowId()) | ||
| .setRunId(workflowExec.getRunId()) | ||
| .setEventRef( | ||
| Link.WorkflowEvent.EventReference.newBuilder() | ||
| .setEventType(EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED)) | ||
| .build(); | ||
| } | ||
| io.temporal.api.nexus.v1.Link nexusLink = workflowEventToNexusLink(workflowEventLink); | ||
| if (nexusLink != null) { | ||
| try { | ||
| ctx.addLinks(nexusProtoLinkToLink(nexusLink)); | ||
| } catch (URISyntaxException e) { | ||
| throw new HandlerException(HandlerException.ErrorType.INTERNAL, "failed to parse URI", e); | ||
| } | ||
| } | ||
|
|
||
| return response; | ||
| } | ||
|
|
||
| private NexusStartWorkflowHelper() {} | ||
| } |
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
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.
Generic token loader validates workflow-specific field
Low Severity
loadOperationTokenis documented as a type-agnostic method for "cancel dispatch where the token type determines the cancel behavior," yet it unconditionally validates thatworkflowIdis present. This is a WORKFLOW_RUN-specific invariant baked into a method meant to handle any token type. When a newOperationTokenTypeis added that doesn't carry aworkflowId, this method will incorrectly reject it. TheworkflowIdcheck belongs inloadWorkflowRunOperationTokenor in the type-specific dispatch branch ofTemporalOperationHandler.cancel.Additional Locations (1)
temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationHandler.java#L93-L111Reviewed by Cursor Bugbot for commit ee62ae7. Configure here.