Skip to content

Commit 751a0b6

Browse files
Expose worker versioning via spring boot autoconfig (#1869)
1 parent 717ee05 commit 751a0b6

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/properties/WorkerProperties.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class WorkerProperties {
3232
private final @Nullable Collection<String> activityBeans;
3333
private final @Nullable CapacityConfigurationProperties capacity;
3434
private final @Nullable RateLimitsConfigurationProperties rateLimits;
35+
private final @Nullable BuildIdConfigurationProperties buildId;
3536

3637
@ConstructorBinding
3738
public WorkerProperties(
@@ -40,13 +41,15 @@ public WorkerProperties(
4041
@Nullable Collection<Class<?>> workflowClasses,
4142
@Nullable Collection<String> activityBeans,
4243
@Nullable CapacityConfigurationProperties capacity,
43-
@Nullable RateLimitsConfigurationProperties rateLimits) {
44+
@Nullable RateLimitsConfigurationProperties rateLimits,
45+
@Nullable BuildIdConfigurationProperties buildId) {
4446
this.name = name;
4547
this.taskQueue = taskQueue;
4648
this.workflowClasses = workflowClasses;
4749
this.activityBeans = activityBeans;
4850
this.capacity = capacity;
4951
this.rateLimits = rateLimits;
52+
this.buildId = buildId;
5053
}
5154

5255
@Nonnull
@@ -79,6 +82,11 @@ public RateLimitsConfigurationProperties getRateLimits() {
7982
return rateLimits;
8083
}
8184

85+
@Nullable
86+
public BuildIdConfigurationProperties getBuildId() {
87+
return buildId;
88+
}
89+
8290
public static class CapacityConfigurationProperties {
8391
private final @Nullable Integer maxConcurrentWorkflowTaskExecutors;
8492
private final @Nullable Integer maxConcurrentActivityExecutors;
@@ -166,4 +174,32 @@ public Double getMaxTaskQueueActivitiesPerSecond() {
166174
return maxTaskQueueActivitiesPerSecond;
167175
}
168176
}
177+
178+
public static class BuildIdConfigurationProperties {
179+
private final @Nullable String workerBuildId;
180+
private final @Nullable boolean enabledWorkerVersioning;
181+
182+
/**
183+
* @param workerBuildId defines {@link
184+
* io.temporal.worker.WorkerOptions.Builder#setBuildId(String)}}
185+
* @param enabledWorkerVersioning defines {@link
186+
* io.temporal.worker.WorkerOptions.Builder#setUseBuildIdForVersioning(boolean)}
187+
*/
188+
@ConstructorBinding
189+
public BuildIdConfigurationProperties(
190+
@Nullable String workerBuildId, @Nullable boolean enabledWorkerVersioning) {
191+
this.workerBuildId = workerBuildId;
192+
this.enabledWorkerVersioning = enabledWorkerVersioning;
193+
}
194+
195+
@Nullable
196+
public String getWorkerBuildId() {
197+
return workerBuildId;
198+
}
199+
200+
@Nullable
201+
public boolean getEnabledWorkerVersioning() {
202+
return enabledWorkerVersioning;
203+
}
204+
}
169205
}

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/template/WorkerOptionsTemplate.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ WorkerOptions createWorkerOptions() {
7272
Optional.ofNullable(rateLimitConfiguration.getMaxTaskQueueActivitiesPerSecond())
7373
.ifPresent(options::setMaxTaskQueueActivitiesPerSecond);
7474
}
75-
}
7675

76+
WorkerProperties.BuildIdConfigurationProperties buildIdConfigurations =
77+
workerProperties.getBuildId();
78+
if (buildIdConfigurations != null) {
79+
Optional.ofNullable(buildIdConfigurations.getWorkerBuildId())
80+
.ifPresent(options::setBuildId);
81+
Optional.ofNullable(buildIdConfigurations.getEnabledWorkerVersioning())
82+
.ifPresent(options::setUseBuildIdForVersioning);
83+
}
84+
}
7785
if (customizer != null) {
7886
options = customizer.customize(options);
7987
if (customizer instanceof WorkerOptionsCustomizer) {

temporal-spring-boot-autoconfigure-alpha/src/test/java/io/temporal/spring/boot/autoconfigure/OptionalWorkerOptionsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ public TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer() {
131131
1.0,
132132
options.getMaxTaskQueueActivitiesPerSecond(),
133133
"Values from the Spring Config should be respected");
134+
135+
assertEquals(
136+
"1.0.0", options.getBuildId(), "Values from the Spring Config should be respected");
137+
assertEquals(
138+
true,
139+
options.isUsingBuildIdForVersioning(),
140+
"Values from the Spring Config should be respected");
134141
return optionsBuilder;
135142
};
136143
return mock(TemporalOptionsCustomizer.class, delegatesTo(customizer));

temporal-spring-boot-autoconfigure-alpha/src/test/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ spring:
9292
rate-limits:
9393
max-worker-activities-per-second: 1.0
9494
max-task-queue-activities-per-second: 1.0
95+
build-id:
96+
worker-build-id: "1.0.0"
97+
enabled-worker-versioning: true
9598
workflow-cache:
9699
max-instances: 10
97100
max-threads: 10

0 commit comments

Comments
 (0)