Skip to content
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

Access to workflow/activity instance from context #2384

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

Provide access to workflow/activity instance from their context. There is some subtly around when the workflow instance is created, I tried to document this in the user visible method.

Note: I did not do anything for Nexus here because the OperationHandler is already passed to the interceptor.

closes: #2361

@Quinn-With-Two-Ns Quinn-With-Two-Ns requested a review from a team as a code owner January 22, 2025 15:54
@@ -147,4 +147,7 @@ public interface ActivityExecutionContext {
* an activity.
*/
WorkflowClient getWorkflowClient();

/** Get the currently running activity instance. */
Object getInstance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question, is this available in the main execute-activity inbound interceptor? Meaning there's no case where it is null (and Java has no concept of accessing the execution context from inside activity class constructors since users invoke those I assume).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

* @apiNote The instance is only available after it has been initialized. This function will
* return null if called before the workflow has been initialized. For example, this could
* happen if the function is called from a {@link WorkflowInit} constructor or {@link
* io.temporal.common.interceptors.WorkflowInboundCallsInterceptor#init(WorkflowOutboundCallsInterceptor)}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long as available in execute of this same interceptor, I think we're good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah in the test I show this is not null in execute

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit b471e13 into temporalio:master Jan 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to workflow/activity instance from context
2 participants