Skip to content

Commit

Permalink
Expose worker versioning via spring boot autoconfig (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Oct 2, 2023
1 parent 717ee05 commit 751a0b6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class WorkerProperties {
private final @Nullable Collection<String> activityBeans;
private final @Nullable CapacityConfigurationProperties capacity;
private final @Nullable RateLimitsConfigurationProperties rateLimits;
private final @Nullable BuildIdConfigurationProperties buildId;

@ConstructorBinding
public WorkerProperties(
Expand All @@ -40,13 +41,15 @@ public WorkerProperties(
@Nullable Collection<Class<?>> workflowClasses,
@Nullable Collection<String> activityBeans,
@Nullable CapacityConfigurationProperties capacity,
@Nullable RateLimitsConfigurationProperties rateLimits) {
@Nullable RateLimitsConfigurationProperties rateLimits,
@Nullable BuildIdConfigurationProperties buildId) {
this.name = name;
this.taskQueue = taskQueue;
this.workflowClasses = workflowClasses;
this.activityBeans = activityBeans;
this.capacity = capacity;
this.rateLimits = rateLimits;
this.buildId = buildId;
}

@Nonnull
Expand Down Expand Up @@ -79,6 +82,11 @@ public RateLimitsConfigurationProperties getRateLimits() {
return rateLimits;
}

@Nullable
public BuildIdConfigurationProperties getBuildId() {
return buildId;
}

public static class CapacityConfigurationProperties {
private final @Nullable Integer maxConcurrentWorkflowTaskExecutors;
private final @Nullable Integer maxConcurrentActivityExecutors;
Expand Down Expand Up @@ -166,4 +174,32 @@ public Double getMaxTaskQueueActivitiesPerSecond() {
return maxTaskQueueActivitiesPerSecond;
}
}

public static class BuildIdConfigurationProperties {
private final @Nullable String workerBuildId;
private final @Nullable boolean enabledWorkerVersioning;

/**
* @param workerBuildId defines {@link
* io.temporal.worker.WorkerOptions.Builder#setBuildId(String)}}
* @param enabledWorkerVersioning defines {@link
* io.temporal.worker.WorkerOptions.Builder#setUseBuildIdForVersioning(boolean)}
*/
@ConstructorBinding
public BuildIdConfigurationProperties(
@Nullable String workerBuildId, @Nullable boolean enabledWorkerVersioning) {
this.workerBuildId = workerBuildId;
this.enabledWorkerVersioning = enabledWorkerVersioning;
}

@Nullable
public String getWorkerBuildId() {
return workerBuildId;
}

@Nullable
public boolean getEnabledWorkerVersioning() {
return enabledWorkerVersioning;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ WorkerOptions createWorkerOptions() {
Optional.ofNullable(rateLimitConfiguration.getMaxTaskQueueActivitiesPerSecond())
.ifPresent(options::setMaxTaskQueueActivitiesPerSecond);
}
}

WorkerProperties.BuildIdConfigurationProperties buildIdConfigurations =
workerProperties.getBuildId();
if (buildIdConfigurations != null) {
Optional.ofNullable(buildIdConfigurations.getWorkerBuildId())
.ifPresent(options::setBuildId);
Optional.ofNullable(buildIdConfigurations.getEnabledWorkerVersioning())
.ifPresent(options::setUseBuildIdForVersioning);
}
}
if (customizer != null) {
options = customizer.customize(options);
if (customizer instanceof WorkerOptionsCustomizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer() {
1.0,
options.getMaxTaskQueueActivitiesPerSecond(),
"Values from the Spring Config should be respected");

assertEquals(
"1.0.0", options.getBuildId(), "Values from the Spring Config should be respected");
assertEquals(
true,
options.isUsingBuildIdForVersioning(),
"Values from the Spring Config should be respected");
return optionsBuilder;
};
return mock(TemporalOptionsCustomizer.class, delegatesTo(customizer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ spring:
rate-limits:
max-worker-activities-per-second: 1.0
max-task-queue-activities-per-second: 1.0
build-id:
worker-build-id: "1.0.0"
enabled-worker-versioning: true
workflow-cache:
max-instances: 10
max-threads: 10
Expand Down

0 comments on commit 751a0b6

Please sign in to comment.