Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.temporal.api.common.v1.*;
import io.temporal.api.failure.v1.Failure;
import io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes;
import io.temporal.api.sdk.v1.UserMetadata;
import io.temporal.common.RetryOptions;
import io.temporal.internal.common.ProtobufTimeUtils;
import java.time.Duration;
Expand All @@ -24,6 +25,7 @@ final class BasicWorkflowContext {
private final WorkflowExecutionStartedEventAttributes startedAttributes;
private final String namespace;
@Nonnull private final WorkflowExecution workflowExecution;
@Nonnull private final UserMetadata userMetadata;

@Nullable private final Payloads lastCompletionResult;

Expand All @@ -33,11 +35,13 @@ final class BasicWorkflowContext {
String namespace,
@Nonnull WorkflowExecution workflowExecution,
WorkflowExecutionStartedEventAttributes startedAttributes,
long runStartedTimestampMillis) {
long runStartedTimestampMillis,
@Nonnull UserMetadata userMetadata) {
this.namespace = namespace;
this.workflowExecution = Preconditions.checkNotNull(workflowExecution);
this.startedAttributes = startedAttributes;
this.runStartedTimestampMillis = runStartedTimestampMillis;
this.userMetadata = userMetadata;
this.lastCompletionResult =
startedAttributes.hasLastCompletionResult()
? startedAttributes.getLastCompletionResult()
Expand Down Expand Up @@ -144,4 +148,9 @@ public RetryOptions getRetryOptions() {
public Priority getPriority() {
return startedAttributes.getPriority();
}

@Nonnull
public UserMetadata getUserMetadata() {
return userMetadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public Functions.Proc1<Exception> getCancellationHandle() {

Payload getMemo(String key);

@Nullable
Payload getStaticSummaryPayload();

@Nullable
Payload getStaticDetailsPayload();

/**
* Requests an activity execution.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ final class ReplayWorkflowContextImpl implements ReplayWorkflowContext {
long runStartedTimestampMillis,
@Nullable String fullReplayDirectQueryName,
SingleWorkerOptions workerOptions,
Scope workflowMetricsScope) {
Scope workflowMetricsScope,
@Nonnull UserMetadata userMetadata) {
this.workflowStateMachines = workflowStateMachines;
this.basicWorkflowContext =
new BasicWorkflowContext(
namespace, workflowExecution, startedAttributes, runStartedTimestampMillis);
namespace,
workflowExecution,
startedAttributes,
runStartedTimestampMillis,
userMetadata);
this.mutableState = new WorkflowMutableState(startedAttributes);
this.fullReplayDirectQueryName = fullReplayDirectQueryName;
this.replayAwareWorkflowMetricsScope =
Expand Down Expand Up @@ -278,6 +283,20 @@ public Priority getPriority() {
return basicWorkflowContext.getPriority();
}

@Override
@Nullable
public Payload getStaticSummaryPayload() {
UserMetadata userMetadata = basicWorkflowContext.getUserMetadata();
return userMetadata.hasSummary() ? userMetadata.getSummary() : null;
}

@Override
@Nullable
public Payload getStaticDetailsPayload() {
UserMetadata userMetadata = basicWorkflowContext.getUserMetadata();
return userMetadata.hasDetails() ? userMetadata.getDetails() : null;
}

@Override
public Functions.Proc1<RuntimeException> newTimer(
Duration delay, UserMetadata metadata, Functions.Proc1<RuntimeException> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.temporal.api.protocol.v1.Message;
import io.temporal.api.query.v1.WorkflowQuery;
import io.temporal.api.query.v1.WorkflowQueryResult;
import io.temporal.api.sdk.v1.UserMetadata;
import io.temporal.api.workflowservice.v1.GetSystemInfoResponse;
import io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponseOrBuilder;
import io.temporal.internal.Config;
Expand Down Expand Up @@ -89,6 +90,7 @@ class ReplayWorkflowRunTaskHandler implements WorkflowRunTaskHandler {
"First event in the history is not WorkflowExecutionStarted");
}
this.startedEvent = startedEvent.getWorkflowExecutionStartedEventAttributes();
UserMetadata userMetadata = startedEvent.getUserMetadata();
this.metricsScope = metricsScope;
this.localActivityDispatcher = localActivityDispatcher;
this.workflow = workflow;
Expand All @@ -111,7 +113,8 @@ class ReplayWorkflowRunTaskHandler implements WorkflowRunTaskHandler {
Timestamps.toMillis(startedEvent.getEventTime()),
fullReplayDirectQueryType,
workerOptions,
metricsScope);
metricsScope,
userMetadata);

this.replayWorkflowExecutor =
new ReplayWorkflowExecutor(workflow, workflowStateMachines, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,26 @@ public static String getCurrentDetails() {
return getRootWorkflowContext().getCurrentDetails();
}

@Nullable
public static String getStaticSummary() {
Payload payload = getRootWorkflowContext().getReplayContext().getStaticSummaryPayload();
if (payload == null) {
return null;
}
return getDataConverterWithCurrentWorkflowContext()
.fromPayload(payload, String.class, String.class);
}

@Nullable
public static String getStaticDetails() {
Payload payload = getRootWorkflowContext().getReplayContext().getStaticDetailsPayload();
if (payload == null) {
return null;
}
return getDataConverterWithCurrentWorkflowContext()
.fromPayload(payload, String.class, String.class);
}

@Nullable
public static Object getInstance() {
return getRootWorkflowContext().getInstance();
Expand Down
25 changes: 25 additions & 0 deletions temporal-sdk/src/main/java/io/temporal/workflow/Workflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,31 @@ public static String getCurrentDetails() {
return WorkflowInternal.getCurrentDetails();
}

/**
* Get the fixed summary for this workflow execution that was set at workflow start. This can be
* in single-line Temporal markdown format.
*
* @return the static summary, or null if not set
*/
@Experimental
@Nullable
public static String getStaticSummary() {
return WorkflowInternal.getStaticSummary();
}

/**
* Get the fixed details for this workflow execution that were set at workflow start. This can be
* in Temporal markdown format and can span multiple lines. Unlike {@link #getCurrentDetails()},
* this value cannot be updated during workflow execution.
*
* @return the static details, or null if not set
*/
@Experimental
@Nullable
public static String getStaticDetails() {
return WorkflowInternal.getStaticDetails();
}

/**
* Get the currently running workflow instance.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.temporal.workflow;

import static io.temporal.testing.internal.SDKTestOptions.newWorkflowOptionsWithTimeouts;
import static org.junit.Assert.assertEquals;

import io.temporal.client.WorkflowOptions;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import org.junit.Rule;
import org.junit.Test;

public class WorkflowStaticSummaryTest {

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(WorkflowReadingStaticMetadata.class)
.build();

static final String SUMMARY = "my-static-summary";
static final String DETAILS = "my-static-details";

@Test
public void testGetStaticSummaryAndDetails() {
WorkflowOptions options =
newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder()
.setStaticSummary(SUMMARY)
.setStaticDetails(DETAILS)
.build();
TestStaticMetadataWorkflow stub =
testWorkflowRule
.getWorkflowClient()
.newWorkflowStub(TestStaticMetadataWorkflow.class, options);

String result = stub.execute();
assertEquals(SUMMARY + "|" + DETAILS, result);
}

@Test
public void testGetStaticSummaryAndDetailsWhenNotSet() {
WorkflowOptions options = newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue());
TestStaticMetadataWorkflow stub =
testWorkflowRule
.getWorkflowClient()
.newWorkflowStub(TestStaticMetadataWorkflow.class, options);

String result = stub.execute();
assertEquals("null|null", result);
}

@WorkflowInterface
public interface TestStaticMetadataWorkflow {
@WorkflowMethod
String execute();
}

public static class WorkflowReadingStaticMetadata implements TestStaticMetadataWorkflow {
@Override
public String execute() {
return Workflow.getStaticSummary() + "|" + Workflow.getStaticDetails();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ public Payload getMemo(String key) {
throw new UnsupportedOperationException("not implemented");
}

@Override
@Nullable
public Payload getStaticSummaryPayload() {
return null;
}

@Override
@Nullable
public Payload getStaticDetailsPayload() {
return null;
}

@Override
@Nullable
public SearchAttributes getSearchAttributes() {
Expand Down
Loading