Skip to content

Commit 0d847a6

Browse files
authored
Add identity to WorkflowOptions (#2080)
Provides the ability to override identity specified in a WorkflowClient
1 parent 5e5cf0b commit 0d847a6

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

temporal-sdk/src/main/java/io/temporal/worker/Worker.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,15 @@ private static SingleWorkerOptions.Builder toSingleWorkerOptions(
594594
} else if (clientOptions.getBinaryChecksum() != null) {
595595
buildId = clientOptions.getBinaryChecksum();
596596
}
597+
598+
String identity = clientOptions.getIdentity();
599+
if (options.getIdentity() != null) {
600+
identity = options.getIdentity();
601+
}
602+
597603
return SingleWorkerOptions.newBuilder()
598604
.setDataConverter(clientOptions.getDataConverter())
599-
.setIdentity(clientOptions.getIdentity())
605+
.setIdentity(identity)
600606
.setBuildId(buildId)
601607
.setUseBuildIdForVersioning(options.isUsingBuildIdForVersioning())
602608
.setEnableLoggingInReplay(factoryOptions.isEnableLoggingInReplay())

temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public static final class Builder {
8686
private SlotSupplier<WorkflowSlotInfo> workflowSlotSupplier;
8787
private SlotSupplier<ActivitySlotInfo> activitySlotSupplier;
8888
private SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier;
89+
private String identity;
8990

9091
private Builder() {}
9192

@@ -416,6 +417,12 @@ public void setLocalActivitySlotSupplier(
416417
this.localActivitySlotSupplier = localActivitySlotSupplier;
417418
}
418419

420+
/** Override identity of the worker primary specified in a WorkflowClient options. */
421+
public Builder setIdentity(String identity) {
422+
this.identity = identity;
423+
return this;
424+
}
425+
419426
public WorkerOptions build() {
420427
return new WorkerOptions(
421428
maxWorkerActivitiesPerSecond,
@@ -436,7 +443,8 @@ public WorkerOptions build() {
436443
disableEagerExecution,
437444
useBuildIdForVersioning,
438445
buildId,
439-
stickyTaskQueueDrainTimeout);
446+
stickyTaskQueueDrainTimeout,
447+
identity);
440448
}
441449

442450
public WorkerOptions validateAndBuildWithDefaults() {
@@ -525,7 +533,8 @@ public WorkerOptions validateAndBuildWithDefaults() {
525533
buildId,
526534
stickyTaskQueueDrainTimeout == null
527535
? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
528-
: stickyTaskQueueDrainTimeout);
536+
: stickyTaskQueueDrainTimeout,
537+
identity);
529538
}
530539
}
531540

@@ -548,6 +557,7 @@ public WorkerOptions validateAndBuildWithDefaults() {
548557
private final boolean useBuildIdForVersioning;
549558
private final String buildId;
550559
private final Duration stickyTaskQueueDrainTimeout;
560+
private final String identity;
551561

552562
private WorkerOptions(
553563
double maxWorkerActivitiesPerSecond,
@@ -568,7 +578,8 @@ private WorkerOptions(
568578
boolean disableEagerExecution,
569579
boolean useBuildIdForVersioning,
570580
String buildId,
571-
Duration stickyTaskQueueDrainTimeout) {
581+
Duration stickyTaskQueueDrainTimeout,
582+
String identity) {
572583
this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
573584
this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
574585
this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
@@ -588,6 +599,7 @@ private WorkerOptions(
588599
this.useBuildIdForVersioning = useBuildIdForVersioning;
589600
this.buildId = buildId;
590601
this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
602+
this.identity = identity;
591603
}
592604

593605
public double getMaxWorkerActivitiesPerSecond() {
@@ -683,6 +695,11 @@ public SlotSupplier<LocalActivitySlotInfo> getLocalActivitySlotSupplier() {
683695
return localActivitySlotSupplier;
684696
}
685697

698+
@Nullable
699+
public String getIdentity() {
700+
return identity;
701+
}
702+
686703
@Override
687704
public boolean equals(Object o) {
688705
if (this == o) return true;
@@ -706,7 +723,8 @@ && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond
706723
&& Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
707724
&& Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
708725
&& Objects.equals(buildId, that.buildId)
709-
&& Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout);
726+
&& Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
727+
&& Objects.equals(identity, that.identity);
710728
}
711729

712730
@Override
@@ -730,7 +748,8 @@ public int hashCode() {
730748
disableEagerExecution,
731749
useBuildIdForVersioning,
732750
buildId,
733-
stickyTaskQueueDrainTimeout);
751+
stickyTaskQueueDrainTimeout,
752+
identity);
734753
}
735754

736755
@Override
@@ -775,6 +794,8 @@ public String toString() {
775794
+ '\''
776795
+ ", stickyTaskQueueDrainTimeout="
777796
+ stickyTaskQueueDrainTimeout
797+
+ ", identity="
798+
+ identity
778799
+ '}';
779800
}
780801
}

0 commit comments

Comments
 (0)