Skip to content

Commit

Permalink
Add activity summary (#2306)
Browse files Browse the repository at this point in the history
Add activity summary
  • Loading branch information
Quinn-With-Two-Ns authored Nov 4, 2024
1 parent f6bf576 commit c8a27ce
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.base.Objects;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.common.Experimental;
import io.temporal.common.MethodRetry;
import io.temporal.common.RetryOptions;
import io.temporal.common.VersioningIntent;
Expand Down Expand Up @@ -64,6 +65,7 @@ public static final class Builder {
private ActivityCancellationType cancellationType;
private boolean disableEagerExecution;
private VersioningIntent versioningIntent;
private String summary;

private Builder() {}

Expand All @@ -81,6 +83,7 @@ private Builder(ActivityOptions options) {
this.cancellationType = options.cancellationType;
this.disableEagerExecution = options.disableEagerExecution;
this.versioningIntent = options.versioningIntent;
this.summary = options.summary;
}

/**
Expand Down Expand Up @@ -243,6 +246,18 @@ public Builder setVersioningIntent(VersioningIntent versioningIntent) {
return this;
}

/**
* Single-line fixed summary for this activity that will appear in UI/CLI. This can be in
* single-line Temporal Markdown format.
*
* <p>Default is none/empty.
*/
@Experimental
public Builder setSummary(String summary) {
this.summary = summary;
return this;
}

public Builder mergeActivityOptions(ActivityOptions override) {
if (override == null) {
return this;
Expand Down Expand Up @@ -274,6 +289,7 @@ public Builder mergeActivityOptions(ActivityOptions override) {
if (override.versioningIntent != VersioningIntent.VERSIONING_INTENT_UNSPECIFIED) {
this.versioningIntent = override.versioningIntent;
}
this.summary = (override.summary == null) ? this.summary : override.summary;
return this;
}

Expand All @@ -296,7 +312,8 @@ public ActivityOptions build() {
contextPropagators,
cancellationType,
disableEagerExecution,
versioningIntent);
versioningIntent,
summary);
}

public ActivityOptions validateAndBuildWithDefaults() {
Expand All @@ -312,7 +329,8 @@ public ActivityOptions validateAndBuildWithDefaults() {
disableEagerExecution,
versioningIntent == null
? VersioningIntent.VERSIONING_INTENT_UNSPECIFIED
: versioningIntent);
: versioningIntent,
summary);
}
}

Expand All @@ -326,6 +344,7 @@ public ActivityOptions validateAndBuildWithDefaults() {
private final ActivityCancellationType cancellationType;
private final boolean disableEagerExecution;
private final VersioningIntent versioningIntent;
private final String summary;

private ActivityOptions(
Duration heartbeatTimeout,
Expand All @@ -337,7 +356,8 @@ private ActivityOptions(
List<ContextPropagator> contextPropagators,
ActivityCancellationType cancellationType,
boolean disableEagerExecution,
VersioningIntent versioningIntent) {
VersioningIntent versioningIntent,
String summary) {
this.heartbeatTimeout = heartbeatTimeout;
this.scheduleToStartTimeout = scheduleToStartTimeout;
this.scheduleToCloseTimeout = scheduleToCloseTimeout;
Expand All @@ -348,6 +368,7 @@ private ActivityOptions(
this.cancellationType = cancellationType;
this.disableEagerExecution = disableEagerExecution;
this.versioningIntent = versioningIntent;
this.summary = summary;
}

/**
Expand Down Expand Up @@ -417,6 +438,11 @@ public VersioningIntent getVersioningIntent() {
return versioningIntent;
}

@Experimental
public String getSummary() {
return summary;
}

public Builder toBuilder() {
return new Builder(this);
}
Expand All @@ -435,7 +461,8 @@ public boolean equals(Object o) {
&& Objects.equal(retryOptions, that.retryOptions)
&& Objects.equal(contextPropagators, that.contextPropagators)
&& disableEagerExecution == that.disableEagerExecution
&& versioningIntent == that.versioningIntent;
&& versioningIntent == that.versioningIntent
&& Objects.equal(summary, that.summary);
}

@Override
Expand All @@ -450,7 +477,8 @@ public int hashCode() {
contextPropagators,
cancellationType,
disableEagerExecution,
versioningIntent);
versioningIntent,
summary);
}

@Override
Expand All @@ -477,6 +505,8 @@ public String toString() {
+ disableEagerExecution
+ ", versioningIntent="
+ versioningIntent
+ ", summary="
+ summary
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.temporal.api.history.v1.ActivityTaskCompletedEventAttributes;
import io.temporal.api.history.v1.ActivityTaskFailedEventAttributes;
import io.temporal.api.history.v1.ActivityTaskTimedOutEventAttributes;
import io.temporal.api.sdk.v1.UserMetadata;
import io.temporal.workflow.Functions;
import java.util.Optional;
import javax.annotation.Nonnull;
Expand All @@ -54,6 +55,7 @@ final class ActivityStateMachine
private final String activityId;
private final ActivityType activityType;
private final ActivityCancellationType cancellationType;
private UserMetadata userMetadata;

private final Functions.Proc2<Optional<Payloads>, FailureResult> completionCallback;

Expand Down Expand Up @@ -265,16 +267,21 @@ private ActivityStateMachine(
this.activityId = scheduleAttr.getActivityId();
this.activityType = scheduleAttr.getActivityType();
this.cancellationType = parameters.getCancellationType();
this.userMetadata = parameters.getMetadata();
this.completionCallback = completionCallback;
explicitEvent(ExplicitEvent.SCHEDULE);
}

public void createScheduleActivityTaskCommand() {
addCommand(
Command.Builder command =
Command.newBuilder()
.setCommandType(CommandType.COMMAND_TYPE_SCHEDULE_ACTIVITY_TASK)
.setScheduleActivityTaskCommandAttributes(parameters.getAttributes())
.build());
.setScheduleActivityTaskCommandAttributes(parameters.getAttributes());
if (userMetadata != null) {
command.setUserMetadata(userMetadata);
userMetadata = null;
}
addCommand(command.build());
parameters = null; // avoiding retaining large input for the duration of the activity
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@

import io.temporal.activity.ActivityCancellationType;
import io.temporal.api.command.v1.ScheduleActivityTaskCommandAttributes;
import io.temporal.api.sdk.v1.UserMetadata;
import java.util.Objects;

public class ExecuteActivityParameters {

private final ScheduleActivityTaskCommandAttributes.Builder attributes;
private final ActivityCancellationType cancellationType;
private final UserMetadata metadata;

public ExecuteActivityParameters(
ScheduleActivityTaskCommandAttributes.Builder attributes,
ActivityCancellationType cancellationType) {
ActivityCancellationType cancellationType,
UserMetadata metadata) {
this.attributes = Objects.requireNonNull(attributes);
this.cancellationType = Objects.requireNonNull(cancellationType);
this.metadata = metadata;
}

public ScheduleActivityTaskCommandAttributes.Builder getAttributes() {
Expand All @@ -43,4 +47,8 @@ public ScheduleActivityTaskCommandAttributes.Builder getAttributes() {
public ActivityCancellationType getCancellationType() {
return cancellationType;
}

public UserMetadata getMetadata() {
return metadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,11 @@ private ExecuteActivityParameters constructExecuteActivityParameters(
replayContext.getTaskQueue().equals(options.getTaskQueue())));
}

return new ExecuteActivityParameters(attributes, options.getCancellationType());
@Nullable
UserMetadata userMetadata =
makeUserMetaData(options.getSummary(), null, dataConverterWithCurrentWorkflowContext);

return new ExecuteActivityParameters(attributes, options.getCancellationType(), userMetadata);
}

private ExecuteLocalActivityParameters constructExecuteLocalActivityParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -173,7 +173,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -254,7 +254,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -340,7 +340,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -388,7 +388,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -490,7 +490,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -574,7 +574,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -680,7 +680,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -798,7 +798,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -918,7 +918,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -1244,7 +1244,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down Expand Up @@ -1352,7 +1352,7 @@ public void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
ScheduleActivityTaskCommandAttributes.newBuilder().setActivityId("id1");
ExecuteActivityParameters parameters =
new ExecuteActivityParameters(
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED);
attributes, ActivityCancellationType.WAIT_CANCELLATION_COMPLETED, null);
builder
.<Optional<Payloads>, Failure>add2(
(v, c) -> cancellationHandler = stateMachines.scheduleActivityTask(parameters, c))
Expand Down
Loading

0 comments on commit c8a27ce

Please sign in to comment.