• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #348

31 Jul 2026 10:02PM UTC coverage: 68.143% (-0.005%) from 68.148%
#348

push

github

web-flow
Do not send versioning info on worker command channel polls (#2987)

7166 of 12558 branches covered (57.06%)

Branch coverage included in aggregate %.

6 of 22 new or added lines in 2 files covered. (27.27%)

2 existing lines in 2 files now uncovered.

29723 of 41577 relevant lines covered (71.49%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.32
/temporal-sdk/src/main/java/io/temporal/internal/worker/AsyncNexusPollTask.java
1
package io.temporal.internal.worker;
2

3
import static io.temporal.serviceclient.MetricsTag.METRICS_TAGS_CALL_OPTIONS_KEY;
4

5
import com.google.protobuf.Timestamp;
6
import com.uber.m3.tally.Scope;
7
import io.grpc.Context;
8
import io.temporal.api.common.v1.WorkerVersionCapabilities;
9
import io.temporal.api.enums.v1.TaskQueueKind;
10
import io.temporal.api.taskqueue.v1.TaskQueue;
11
import io.temporal.api.workflowservice.v1.GetSystemInfoResponse;
12
import io.temporal.api.workflowservice.v1.PollNexusTaskQueueRequest;
13
import io.temporal.api.workflowservice.v1.PollNexusTaskQueueResponse;
14
import io.temporal.internal.common.GrpcUtils;
15
import io.temporal.internal.common.ProtobufTimeUtils;
16
import io.temporal.serviceclient.MetricsTag;
17
import io.temporal.serviceclient.WorkflowServiceStubs;
18
import io.temporal.worker.MetricsType;
19
import io.temporal.worker.PollerTypeMetricsTag;
20
import io.temporal.worker.tuning.SlotPermit;
21
import io.temporal.worker.tuning.SlotReleaseReason;
22
import java.util.Objects;
23
import java.util.concurrent.CompletableFuture;
24
import java.util.function.Supplier;
25
import javax.annotation.Nonnull;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

29
public class AsyncNexusPollTask implements AsyncPoller.PollTaskAsync<NexusTask> {
30
  private static final Logger log = LoggerFactory.getLogger(AsyncNexusPollTask.class);
1✔
31

32
  private final TrackingSlotSupplier<?> slotSupplier;
33
  private final WorkflowServiceStubs service;
34
  private final Scope metricsScope;
35
  private final PollNexusTaskQueueRequest pollRequest;
36
  private final Context.CancellableContext grpcContext = Context.ROOT.withCancellation();
1✔
37
  private final PollerTracker pollerTracker;
38

39
  @SuppressWarnings("deprecation")
40
  public AsyncNexusPollTask(
41
      @Nonnull WorkflowServiceStubs service,
42
      @Nonnull String namespace,
43
      @Nonnull String taskQueue,
44
      @Nonnull String identity,
45
      @Nonnull String workerInstanceKey,
46
      @Nonnull WorkerVersioningOptions versioningOptions,
47
      @Nonnull Scope metricsScope,
48
      @Nonnull Supplier<GetSystemInfoResponse.Capabilities> serverCapabilities,
49
      TrackingSlotSupplier<?> slotSupplier,
50
      @Nonnull PollerTracker pollerTracker) {
51
    this(
×
52
        service,
53
        namespace,
54
        taskQueue,
55
        identity,
56
        workerInstanceKey,
57
        versioningOptions,
58
        metricsScope,
59
        serverCapabilities,
60
        slotSupplier,
61
        pollerTracker,
62
        false);
63
  }
×
64

65
  @SuppressWarnings("deprecation")
66
  public AsyncNexusPollTask(
67
      @Nonnull WorkflowServiceStubs service,
68
      @Nonnull String namespace,
69
      @Nonnull String taskQueue,
70
      @Nonnull String identity,
71
      @Nonnull String workerInstanceKey,
72
      @Nonnull WorkerVersioningOptions versioningOptions,
73
      @Nonnull Scope metricsScope,
74
      @Nonnull Supplier<GetSystemInfoResponse.Capabilities> serverCapabilities,
75
      TrackingSlotSupplier<?> slotSupplier,
76
      @Nonnull PollerTracker pollerTracker,
77
      boolean workerCommandsTaskQueue) {
1✔
78
    this.service = Objects.requireNonNull(service);
1✔
79
    this.metricsScope = Objects.requireNonNull(metricsScope);
1✔
80
    this.slotSupplier = slotSupplier;
1✔
81
    this.pollerTracker = Objects.requireNonNull(pollerTracker);
1✔
82

83
    PollNexusTaskQueueRequest.Builder pollRequest =
84
        PollNexusTaskQueueRequest.newBuilder()
1✔
85
            .setNamespace(namespace)
1✔
86
            .setIdentity(identity)
1✔
87
            .setTaskQueue(
1✔
88
                TaskQueue.newBuilder()
1✔
89
                    .setName(taskQueue)
1✔
90
                    .setKind(
1✔
91
                        workerCommandsTaskQueue
1!
92
                            ? TaskQueueKind.TASK_QUEUE_KIND_WORKER_COMMANDS
×
93
                            : TaskQueueKind.TASK_QUEUE_KIND_NORMAL));
1✔
94

95
    pollRequest.setWorkerInstanceKey(workerInstanceKey);
1✔
96

97
    if (!workerCommandsTaskQueue) {
1!
98
      if (versioningOptions.getWorkerDeploymentOptions() != null) {
1!
NEW
99
        pollRequest.setDeploymentOptions(
×
NEW
100
            WorkerVersioningProtoUtils.deploymentOptionsToProto(
×
NEW
101
                versioningOptions.getWorkerDeploymentOptions()));
×
102
      } else if (serverCapabilities.get().getBuildIdBasedVersioning()) {
1!
NEW
103
        pollRequest.setWorkerVersionCapabilities(
×
NEW
104
            WorkerVersionCapabilities.newBuilder()
×
NEW
105
                .setBuildId(versioningOptions.getBuildId())
×
NEW
106
                .setUseVersioning(versioningOptions.isUsingVersioning())
×
NEW
107
                .build());
×
108
      }
109
    }
110
    this.pollRequest = pollRequest.build();
1✔
111
  }
1✔
112

113
  @Override
114
  @SuppressWarnings("deprecation")
115
  public CompletableFuture<NexusTask> poll(SlotPermit permit) {
116
    if (log.isTraceEnabled()) {
1!
117
      log.trace("poll request begin: " + pollRequest);
×
118
    }
119

120
    MetricsTag.tagged(metricsScope, PollerTypeMetricsTag.PollerType.NEXUS_TASK)
1✔
121
        .gauge(MetricsType.NUM_POLLERS)
1✔
122
        .update(pollerTracker.pollStarted());
1✔
123

124
    CompletableFuture<PollNexusTaskQueueResponse> response = null;
1✔
125
    try {
126
      response =
1✔
127
          grpcContext.call(
1✔
128
              () ->
129
                  GrpcUtils.toCompletableFuture(
1✔
130
                      service
131
                          .futureStub()
1✔
132
                          .withOption(METRICS_TAGS_CALL_OPTIONS_KEY, metricsScope)
1✔
133
                          .pollNexusTaskQueue(pollRequest)));
1✔
134
    } catch (Exception e) {
×
135
      MetricsTag.tagged(metricsScope, PollerTypeMetricsTag.PollerType.NEXUS_TASK)
×
136
          .gauge(MetricsType.NUM_POLLERS)
×
137
          .update(pollerTracker.pollCompleted());
×
138
      throw new RuntimeException(e);
×
139
    }
1✔
140

141
    return response
1✔
142
        .thenApply(
1✔
143
            r -> {
144
              if (r == null || r.getTaskToken().isEmpty()) {
1!
145
                metricsScope.counter(MetricsType.NEXUS_POLL_NO_TASK_COUNTER).inc(1);
×
146
                return null;
×
147
              }
148
              pollerTracker.pollSucceeded();
1✔
149
              Timestamp startedTime = ProtobufTimeUtils.getCurrentProtoTime();
1✔
150
              metricsScope
1✔
151
                  .timer(MetricsType.NEXUS_SCHEDULE_TO_START_LATENCY)
1✔
152
                  .record(
1✔
153
                      ProtobufTimeUtils.toM3Duration(
1✔
154
                          startedTime, r.getRequest().getScheduledTime()));
1✔
155
              return new NexusTask(
1✔
156
                  r,
157
                  permit,
158
                  () -> slotSupplier.releaseSlot(SlotReleaseReason.taskComplete(), permit));
1✔
159
            })
160
        .whenComplete(
1✔
161
            (r, e) -> {
162
              MetricsTag.tagged(metricsScope, PollerTypeMetricsTag.PollerType.NEXUS_TASK)
1✔
163
                  .gauge(MetricsType.NUM_POLLERS)
1✔
164
                  .update(pollerTracker.pollCompleted());
1✔
165
            });
1✔
166
  }
167

168
  @Override
169
  public void cancel(Throwable cause) {
170
    grpcContext.cancel(cause);
1✔
171
  }
1✔
172

173
  @Override
174
  public String getLabel() {
175
    return "AsyncNexusPollTask";
1✔
176
  }
177

178
  @Override
179
  public String toString() {
180
    return "AsyncNexusPollTask{}";
×
181
  }
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc