Skip to content
Closed
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 @@ -18,6 +18,7 @@ public static final class Builder {
private ScheduleOverlapPolicy overlap;
private Duration catchupWindow;
private boolean pauseOnFailure;
private boolean keepOriginalWorkflowId;

private Builder() {}

Expand All @@ -28,6 +29,7 @@ private Builder(SchedulePolicy options) {
this.overlap = options.overlap;
this.catchupWindow = options.catchupWindow;
this.pauseOnFailure = options.pauseOnFailure;
this.keepOriginalWorkflowId = options.keepOriginalWorkflowId;
}

/** Set the policy for what happens when an action is started while another is still running. */
Expand All @@ -51,23 +53,38 @@ public Builder setPauseOnFailure(boolean pauseOnFailure) {
return this;
}

/**
* If true and the action starts a workflow, a timestamp will not be appended to the configured
* workflow id.
*/
public Builder setKeepOriginalWorkflowId(boolean keepOriginalWorkflowId) {
this.keepOriginalWorkflowId = keepOriginalWorkflowId;
return this;
}

public SchedulePolicy build() {
return new SchedulePolicy(
overlap == null ? ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_SKIP : overlap,
catchupWindow,
pauseOnFailure);
pauseOnFailure,
keepOriginalWorkflowId);
}
}

private final ScheduleOverlapPolicy overlap;
private final Duration catchupWindow;
private final boolean pauseOnFailure;
private final boolean keepOriginalWorkflowId;

private SchedulePolicy(
ScheduleOverlapPolicy overlap, Duration catchupWindow, boolean pauseOnFailure) {
ScheduleOverlapPolicy overlap,
Duration catchupWindow,
boolean pauseOnFailure,
boolean keepOriginalWorkflowId) {
this.overlap = overlap;
this.catchupWindow = catchupWindow;
this.pauseOnFailure = pauseOnFailure;
this.keepOriginalWorkflowId = keepOriginalWorkflowId;
}

/**
Expand Down Expand Up @@ -98,19 +115,30 @@ public boolean isPauseOnFailure() {
return pauseOnFailure;
}

/**
* Gets whether the scheduled workflow should keep the original workflow id without timestamp
* suffixing.
*
* @return if the original workflow id should be kept as-is
*/
public boolean isKeepOriginalWorkflowId() {
return keepOriginalWorkflowId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SchedulePolicy that = (SchedulePolicy) o;
return pauseOnFailure == that.pauseOnFailure
&& keepOriginalWorkflowId == that.keepOriginalWorkflowId
&& overlap == that.overlap
&& Objects.equals(catchupWindow, that.catchupWindow);
}

@Override
public int hashCode() {
return Objects.hash(overlap, catchupWindow, pauseOnFailure);
return Objects.hash(overlap, catchupWindow, pauseOnFailure, keepOriginalWorkflowId);
}

@Override
Expand All @@ -122,6 +150,8 @@ public String toString() {
+ catchupWindow
+ ", pauseOnFailure="
+ pauseOnFailure
+ ", keepOriginalWorkflowId="
+ keepOriginalWorkflowId
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public SchedulePolicies policyToProto(SchedulePolicy policy) {
builder.setCatchupWindow(ProtobufTimeUtils.toProtoDuration(policy.getCatchupWindow()));
}
builder.setPauseOnFailure(policy.isPauseOnFailure());
builder.setKeepOriginalWorkflowId(policy.isKeepOriginalWorkflowId());
builder.setOverlapPolicy(policy.getOverlap());
return builder.build();
}
Expand Down Expand Up @@ -487,6 +488,7 @@ public SchedulePolicy protoToPolicy(@Nullable SchedulePolicies policy) {
SchedulePolicy.Builder policyBuilder =
SchedulePolicy.newBuilder()
.setPauseOnFailure(policy.getPauseOnFailure())
.setKeepOriginalWorkflowId(policy.getKeepOriginalWorkflowId())
.setOverlap(policy.getOverlapPolicy());
if (policy.hasCatchupWindow()) {
policyBuilder.setCatchupWindow(ProtobufTimeUtils.toJavaDuration(policy.getCatchupWindow()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public void describeSchedules() {
.setOverlap(ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER_ONE)
.setPauseOnFailure(true)
.setCatchupWindow(Duration.ofMinutes(5))
.setKeepOriginalWorkflowId(true)
.build())
.build();
ScheduleHandle handle = client.createSchedule(scheduleId, schedule, options);
Expand Down Expand Up @@ -391,6 +392,53 @@ public void describeSchedules() {
}
}

@Test
public void keepOriginalWorkflowIdPolicyOnCreate() {
ScheduleClient client = createScheduleClient();
String scheduleId = UUID.randomUUID().toString();
Schedule schedule =
createTestSchedule()
.setPolicy(SchedulePolicy.newBuilder().setKeepOriginalWorkflowId(true).build())
.build();
ScheduleHandle handle =
client.createSchedule(scheduleId, schedule, ScheduleOptions.newBuilder().build());
try {
ScheduleDescription description = handle.describe();
Assert.assertTrue(description.getSchedule().getPolicy().isKeepOriginalWorkflowId());
} finally {
handle.delete();
}
}

@Test
public void keepOriginalWorkflowIdPolicyCanBeUpdated() {
ScheduleClient client = createScheduleClient();
String scheduleId = UUID.randomUUID().toString();
Schedule schedule = createTestSchedule().setPolicy(SchedulePolicy.newBuilder().build()).build();
ScheduleHandle handle =
client.createSchedule(scheduleId, schedule, ScheduleOptions.newBuilder().build());
try {
ScheduleDescription description = handle.describe();
Assert.assertFalse(description.getSchedule().getPolicy().isKeepOriginalWorkflowId());

handle.update(
(ScheduleUpdateInput input) -> {
SchedulePolicy existingPolicy = input.getDescription().getSchedule().getPolicy();
SchedulePolicy.Builder policyBuilder = SchedulePolicy.newBuilder(existingPolicy);
policyBuilder.setKeepOriginalWorkflowId(true);
return new ScheduleUpdate(
Schedule.newBuilder(input.getDescription().getSchedule())
.setPolicy(policyBuilder.build())
.build());
});

description = handle.describe();
Assert.assertTrue(description.getSchedule().getPolicy().isKeepOriginalWorkflowId());
} finally {
handle.delete();
}
}

@Test
public void updateSchedules() {
ScheduleClient client = createScheduleClient();
Expand Down
Loading