Add @TemporalOperation annotation for Nexus operations #2928
Add @TemporalOperation annotation for Nexus operations #2928Quinn-With-Two-Ns wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 240ac3836c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1,4 +1,5 @@ | |||
| rootProject.name='temporal-java-sdk' | |||
| includeBuild('../nexus/nexus-sdk-java') | |||
There was a problem hiding this comment.
Remove the hard-coded sibling composite build
In a normal checkout that does not also have ../nexus/nexus-sdk-java, Gradle evaluates this settings file before any task and the build is blocked by the missing included build; Gradle documents includeBuild here as adding another build to the composite, while the CLI --include-build is the optional one-off form. Please don't commit a machine-local composite path; use the published dependency or make local Nexus development opt-in so ./gradlew test works from a clean sdk-java checkout.
Useful? React with 👍 / 👎.
| * <p>For the common case (default cancel behavior), prefer {@link TemporalOperation}, which | ||
| * collapses the operation factory into the method itself. Subclass this class only when you need to | ||
| * customize cancel behavior. Override {@link #cancelWorkflowRun} to change how workflow-run | ||
| * cancellations are handled. The {@link #start} and {@link #cancel} methods should not be | ||
| * overridden — they contain the core dispatch logic. |
There was a problem hiding this comment.
Preserve the existing factory method
This change deletes the public TemporalOperationHandler.create(...) API, but existing users implementing @OperationImpl with the documented factory will fail to compile after upgrading even though the new annotation is only additive. The repository guidance says to avoid public API signature changes; keeping this factory as a compatibility wrapper around the constructor lets existing custom handlers continue to build while still documenting @TemporalOperation as the preferred path.
Useful? React with 👍 / 👎.
What was changed
Introduces
@TemporalOperation, a method-level annotation that declares a Temporal-backed Nexus operation directly on a@ServiceImplclass. The framework wraps the annotated method as the start handler with default cancel behavior, removing the boilerplate of a separate TemporalOperationHandler for the common workflow-run case.@OperationImplis still supported for custom cancel or handler composition, and both annotations can coexist on the same service (but not the same method).Why?
Make it easier to define Nexus Operation Handlers by having less boilerplate between the interface and the implementation
Checklist
Closes
How was this tested:
Note requires nexus-rpc/sdk-java#46 to be merged
Note
Medium Risk
Changes Nexus service registration and handler dispatch for all workers; mis-annotated services fail at registration, but runtime behavior for existing
@OperationImplpaths should be unchanged.Overview
Adds
@TemporalOperation, a method-level annotation on@ServiceImplclasses so the annotated method is the Nexus start handler (wrapped inTemporalOperationHandlerwith default cancel behavior) instead of returning anOperationHandlervia@OperationImpl+TemporalOperationHandler.create.TemporalOperationProcessorplugs aMethodExtensionintoServiceImplInstance.fromInstanceto scan@TemporalOperationmethods, validate signatures(TemporalOperationStartContext, TemporalNexusClient, input)andTemporalOperationResult<R>, and bind them withMethodHandle. Nexus worker registration, Spring Boot worker setup, and test utilities now callTemporalOperationProcessor.processinstead ofServiceImplInstance.fromInstancealone.TemporalOperationHandler.createis removed; docs steer common cases to@TemporalOperationand custom cancel to subclassingTemporalOperationHandlerwith@OperationImpl. Existing generic-handler tests are migrated to@TemporalOperation; new unit and E2E tests (Java and Kotlin) cover validation and mixed@TemporalOperation/@OperationImplservices. Build addsincludeBuild('../nexus/nexus-sdk-java')for the nexusrpcMethodExtensionAPI.Reviewed by Cursor Bugbot for commit 240ac38. Bugbot is set up for automated code reviews on this repo. Configure here.