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

temporalio / sdk-java / #278

08 Jul 2024 04:42PM UTC coverage: 77.565% (+0.1%) from 77.469%
#278

push

github

web-flow
Revert configurable slot provider (#2134)

* Revert "Resource based tuner (#2110)"

This reverts commit 8a2d5cdcc.

* Revert "Slot supplier interface & fixed-size implementation (#2014)"

This reverts commit d2a06fc6f.

* Fix merge conflict

* Keep Publish Test Report step

* Add tests for worker slots

* Fix white space

* One other whitespace change

117 of 133 new or added lines in 17 files covered. (87.97%)

5 existing lines in 5 files now uncovered.

19088 of 24609 relevant lines covered (77.57%)

0.78 hits per line

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

82.01
/temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.worker;
22

23
import static java.lang.Double.compare;
24

25
import com.google.common.base.Preconditions;
26
import io.temporal.common.Experimental;
27
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
28
import java.time.Duration;
29
import java.util.Objects;
30
import javax.annotation.Nonnull;
31
import javax.annotation.Nullable;
32

33
public final class WorkerOptions {
34

35
  public static Builder newBuilder() {
36
    return new Builder();
1✔
37
  }
38

39
  public static Builder newBuilder(WorkerOptions options) {
40
    return new Builder(options);
1✔
41
  }
42

43
  public static WorkerOptions getDefaultInstance() {
44
    return DEFAULT_INSTANCE;
1✔
45
  }
46

47
  static final Duration DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT = Duration.ofSeconds(5);
1✔
48

49
  static final Duration DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT = Duration.ofSeconds(0);
1✔
50

51
  private static final WorkerOptions DEFAULT_INSTANCE;
52

53
  static {
54
    DEFAULT_INSTANCE = WorkerOptions.newBuilder().validateAndBuildWithDefaults();
1✔
55
  }
1✔
56

57
  public static final class Builder {
58

59
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS = 5;
60
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS = 5;
61
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE = 200;
62
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE = 200;
63
    private static final int DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE = 200;
64
    private static final long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
65
    private static final Duration DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL = Duration.ofSeconds(60);
1✔
66
    private static final Duration DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL =
1✔
67
        Duration.ofSeconds(30);
1✔
68

69
    private double maxWorkerActivitiesPerSecond;
70
    private int maxConcurrentActivityExecutionSize;
71
    private int maxConcurrentWorkflowTaskExecutionSize;
72
    private int maxConcurrentLocalActivityExecutionSize;
73
    private double maxTaskQueueActivitiesPerSecond;
74
    private int maxConcurrentWorkflowTaskPollers;
75
    private int maxConcurrentActivityTaskPollers;
76
    private boolean localActivityWorkerOnly;
77
    private long defaultDeadlockDetectionTimeout;
78
    private Duration maxHeartbeatThrottleInterval;
79
    private Duration defaultHeartbeatThrottleInterval;
80
    private Duration stickyQueueScheduleToStartTimeout;
81
    private boolean disableEagerExecution;
82
    private String buildId;
83
    private boolean useBuildIdForVersioning;
84
    private Duration stickyTaskQueueDrainTimeout;
85
    private String identity;
86

87
    private Builder() {}
88

89
    private Builder(WorkerOptions o) {
1✔
90
      if (o == null) {
1✔
91
        return;
1✔
92
      }
93
      this.maxWorkerActivitiesPerSecond = o.maxWorkerActivitiesPerSecond;
1✔
94
      this.maxConcurrentActivityExecutionSize = o.maxConcurrentActivityExecutionSize;
1✔
95
      this.maxConcurrentWorkflowTaskExecutionSize = o.maxConcurrentWorkflowTaskExecutionSize;
1✔
96
      this.maxConcurrentLocalActivityExecutionSize = o.maxConcurrentLocalActivityExecutionSize;
1✔
97
      this.maxTaskQueueActivitiesPerSecond = o.maxTaskQueueActivitiesPerSecond;
1✔
98
      this.maxConcurrentWorkflowTaskPollers = o.maxConcurrentWorkflowTaskPollers;
1✔
99
      this.maxConcurrentActivityTaskPollers = o.maxConcurrentActivityTaskPollers;
1✔
100
      this.localActivityWorkerOnly = o.localActivityWorkerOnly;
1✔
101
      this.defaultDeadlockDetectionTimeout = o.defaultDeadlockDetectionTimeout;
1✔
102
      this.maxHeartbeatThrottleInterval = o.maxHeartbeatThrottleInterval;
1✔
103
      this.defaultHeartbeatThrottleInterval = o.defaultHeartbeatThrottleInterval;
1✔
104
      this.stickyQueueScheduleToStartTimeout = o.stickyQueueScheduleToStartTimeout;
1✔
105
      this.disableEagerExecution = o.disableEagerExecution;
1✔
106
      this.useBuildIdForVersioning = o.useBuildIdForVersioning;
1✔
107
      this.buildId = o.buildId;
1✔
108
      this.stickyTaskQueueDrainTimeout = o.stickyTaskQueueDrainTimeout;
1✔
109
    }
1✔
110

111
    /**
112
     * @param maxWorkerActivitiesPerSecond Maximum number of activities started per second by this
113
     *     worker. Default is 0 which means unlimited.
114
     * @return {@code this}
115
     *     <p>If worker is not fully loaded while tasks are backing up on the service consider
116
     *     increasing {@link #setMaxConcurrentActivityTaskPollers(int)}.
117
     *     <p>Note that this is a per worker limit. Use {@link
118
     *     #setMaxTaskQueueActivitiesPerSecond(double)} to set per task queue limit across multiple
119
     *     workers.
120
     */
121
    public Builder setMaxWorkerActivitiesPerSecond(double maxWorkerActivitiesPerSecond) {
122
      if (maxWorkerActivitiesPerSecond < 0) {
1✔
123
        throw new IllegalArgumentException(
×
124
            "Negative maxWorkerActivitiesPerSecond value: " + maxWorkerActivitiesPerSecond);
125
      }
126
      this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
127
      return this;
1✔
128
    }
129

130
    /**
131
     * @param maxConcurrentActivityExecutionSize Maximum number of activities executed in parallel.
132
     *     Default is 200, which is chosen if set to zero.
133
     * @return {@code this}
134
     */
135
    public Builder setMaxConcurrentActivityExecutionSize(int maxConcurrentActivityExecutionSize) {
136
      if (maxConcurrentActivityExecutionSize < 0) {
1✔
137
        throw new IllegalArgumentException(
×
138
            "Negative maxConcurrentActivityExecutionSize value: "
139
                + maxConcurrentActivityExecutionSize);
140
      }
141
      this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
142
      return this;
1✔
143
    }
144

145
    /**
146
     * @param maxConcurrentWorkflowTaskExecutionSize Maximum number of simultaneously executed
147
     *     workflow tasks. Default is 200, which is chosen if set to zero.
148
     * @return {@code this}
149
     *     <p>Note that this is not related to the total number of open workflows which do not need
150
     *     to be loaded in a worker when they are not making state transitions.
151
     */
152
    public Builder setMaxConcurrentWorkflowTaskExecutionSize(
153
        int maxConcurrentWorkflowTaskExecutionSize) {
154
      if (maxConcurrentWorkflowTaskExecutionSize < 0) {
1✔
155
        throw new IllegalArgumentException(
×
156
            "Negative maxConcurrentWorkflowTaskExecutionSize value: "
157
                + maxConcurrentWorkflowTaskExecutionSize);
158
      }
159
      this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
160
      return this;
1✔
161
    }
162

163
    /**
164
     * @param maxConcurrentLocalActivityExecutionSize Maximum number of local activities executed in
165
     *     parallel. Default is 200, which is chosen if set to zero.
166
     * @return {@code this}
167
     */
168
    public Builder setMaxConcurrentLocalActivityExecutionSize(
169
        int maxConcurrentLocalActivityExecutionSize) {
170
      if (maxConcurrentLocalActivityExecutionSize < 0) {
1✔
171
        throw new IllegalArgumentException(
×
172
            "Negative maxConcurrentLocalActivityExecutionSize value: "
173
                + maxConcurrentLocalActivityExecutionSize);
174
      }
175
      this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
176
      return this;
1✔
177
    }
178

179
    /**
180
     * Optional: Sets the rate limiting on number of activities that can be executed per second.
181
     * This is managed by the server and controls activities per second for the entire task queue
182
     * across all the workers. Notice that the number is represented in double, so that you can set
183
     * it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
184
     * to be executed once every 10 seconds. This can be used to protect down stream services from
185
     * flooding. The zero value of this uses the default value. Default is unlimited.
186
     */
187
    public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
188
      this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
189
      return this;
1✔
190
    }
191

192
    /**
193
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
194
     * workflow tasks. Changing this value will affect the rate at which the worker is able to
195
     * consume tasks from a task queue.
196
     *
197
     * <p>Due to internal logic where pollers alternate between sticky and non-sticky queues, this
198
     * value cannot be 1 and will be adjusted to 2 if set to that value.
199
     *
200
     * <p>Default is 5, which is chosen if set to zero.
201
     */
202
    public Builder setMaxConcurrentWorkflowTaskPollers(int maxConcurrentWorkflowTaskPollers) {
203
      this.maxConcurrentWorkflowTaskPollers = maxConcurrentWorkflowTaskPollers;
1✔
204
      return this;
1✔
205
    }
206

207
    /**
208
     * Number of simultaneous poll requests on workflow task queue. Note that the majority of the
209
     * workflow tasks will be using host local task queue due to caching. So try incrementing {@link
210
     * WorkerFactoryOptions.Builder#setWorkflowHostLocalPollThreadCount(int)} before this one.
211
     *
212
     * <p>Default is 5, which is chosen if set to zero.
213
     *
214
     * @deprecated Use {@link #setMaxConcurrentWorkflowTaskPollers}
215
     */
216
    @Deprecated
217
    public Builder setWorkflowPollThreadCount(int workflowPollThreadCount) {
218
      return setMaxConcurrentWorkflowTaskPollers(workflowPollThreadCount);
×
219
    }
220

221
    /**
222
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
223
     * worker is not throttled due to `MaxActivitiesPerSecond` or
224
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
225
     *
226
     * <p>Default is 5, which is chosen if set to zero.
227
     */
228
    public Builder setMaxConcurrentActivityTaskPollers(int maxConcurrentActivityTaskPollers) {
229
      this.maxConcurrentActivityTaskPollers = maxConcurrentActivityTaskPollers;
1✔
230
      return this;
1✔
231
    }
232

233
    /**
234
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
235
     * worker is not throttled due to `MaxActivitiesPerSecond` or
236
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
237
     *
238
     * <p>Default is 5, which is chosen if set to zero.
239
     *
240
     * @deprecated Use {@link #setMaxConcurrentActivityTaskPollers}
241
     */
242
    @Deprecated
243
    public Builder setActivityPollThreadCount(int activityPollThreadCount) {
244
      return setMaxConcurrentActivityTaskPollers(activityPollThreadCount);
×
245
    }
246

247
    /**
248
     * If set to true worker would only handle workflow tasks and local activities. Non-local
249
     * activities will not be executed by this worker.
250
     *
251
     * <p>Default is false.
252
     */
253
    public Builder setLocalActivityWorkerOnly(boolean localActivityWorkerOnly) {
254
      this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
255
      return this;
1✔
256
    }
257

258
    /**
259
     * @param defaultDeadlockDetectionTimeoutMs time period in ms that will be used to detect
260
     *     workflows deadlock. Default is 1000ms, which is chosen if set to zero.
261
     *     <p>Specifies an amount of time in milliseconds that workflow tasks are allowed to execute
262
     *     without interruption. If workflow task runs longer than specified interval without
263
     *     yielding (like calling an Activity), it will fail automatically.
264
     * @return {@code this}
265
     * @see io.temporal.internal.sync.PotentialDeadlockException
266
     */
267
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeoutMs) {
268
      if (defaultDeadlockDetectionTimeoutMs < 0) {
1✔
269
        throw new IllegalArgumentException(
×
270
            "Negative defaultDeadlockDetectionTimeout value: " + defaultDeadlockDetectionTimeoutMs);
271
      }
272
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeoutMs;
1✔
273
      return this;
1✔
274
    }
275

276
    /**
277
     * @param interval the maximum amount of time between sending each pending heartbeat to the
278
     *     server. Regardless of heartbeat timeout, no pending heartbeat will wait longer than this
279
     *     amount of time to send. Default is 60s, which is chosen if set to null or 0.
280
     * @return {@code this}
281
     */
282
    public Builder setMaxHeartbeatThrottleInterval(@Nullable Duration interval) {
283
      Preconditions.checkArgument(
×
284
          interval == null || !interval.isNegative(),
×
285
          "Negative maxHeartbeatThrottleInterval value: %s",
286
          interval);
287
      this.maxHeartbeatThrottleInterval = interval;
×
288
      return this;
×
289
    }
290

291
    /**
292
     * @param interval the default amount of time between sending each pending heartbeat to the
293
     *     server. This is used if the ActivityOptions do not provide a HeartbeatTimeout. Otherwise,
294
     *     the interval becomes a value a bit smaller than the given HeartbeatTimeout. Default is
295
     *     30s, which is chosen if set to null or 0.
296
     * @return {@code this}
297
     */
298
    public Builder setDefaultHeartbeatThrottleInterval(@Nullable Duration interval) {
299
      Preconditions.checkArgument(
×
300
          interval == null || !interval.isNegative(),
×
301
          "Negative defaultHeartbeatThrottleInterval value: %s",
302
          interval);
303
      this.defaultHeartbeatThrottleInterval = interval;
×
304
      return this;
×
305
    }
306

307
    /**
308
     * Timeout for a workflow task routed to the "sticky worker" - host that has the workflow
309
     * instance cached in memory. Once it times out, then it can be picked up by any worker.
310
     *
311
     * <p>Default value is 5 seconds.
312
     */
313
    public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
314
      this.stickyQueueScheduleToStartTimeout = timeout;
1✔
315
      return this;
1✔
316
    }
317

318
    /**
319
     * Disable eager activities. If set to true, eager execution will not be requested for
320
     * activities requested from workflows bound to this Worker.
321
     *
322
     * <p>Eager activity execution means the server returns requested eager activities directly from
323
     * the workflow task back to this worker which is faster than non-eager which may be dispatched
324
     * to a separate worker.
325
     *
326
     * <p>Defaults to false, meaning that eager activity execution is permitted
327
     */
328
    public Builder setDisableEagerExecution(boolean disableEagerExecution) {
329
      this.disableEagerExecution = disableEagerExecution;
×
330
      return this;
×
331
    }
332

333
    /**
334
     * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
335
     * will only receive tasks which it is compatible with. For more information see: TODO: Doc link
336
     *
337
     * <p>Defaults to false
338
     */
339
    @Experimental
340
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
341
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
342
      return this;
1✔
343
    }
344

345
    /**
346
     * Set a unique identifier for this worker. The identifier should be stable with respect to the
347
     * code the worker uses for workflows, activities, and interceptors. For more information see:
348
     * TODO: Doc link
349
     *
350
     * <p>A Build Id must be set if {@link #setUseBuildIdForVersioning(boolean)} is set true.
351
     */
352
    @Experimental
353
    public Builder setBuildId(String buildId) {
354
      this.buildId = buildId;
1✔
355
      return this;
1✔
356
    }
357

358
    /**
359
     * During graceful shutdown, as when calling {@link WorkerFactory#shutdown()}, if the workflow
360
     * cache is enabled, this timeout controls how long to wait for the sticky task queue to drain
361
     * before shutting down the worker. If set the worker will stop making new poll requests on the
362
     * normal task queue, but will continue to poll the sticky task queue until the timeout is
363
     * reached. This value should always be greater than clients rpc long poll timeout, which can be
364
     * set via {@link WorkflowServiceStubsOptions.Builder#setRpcLongPollTimeout(Duration)}.
365
     *
366
     * <p>Default is not to wait.
367
     */
368
    @Experimental
369
    public Builder setStickyTaskQueueDrainTimeout(Duration stickyTaskQueueDrainTimeout) {
370
      this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
371
      return this;
1✔
372
    }
373

374
    /** Override identity of the worker primary specified in a WorkflowClient options. */
375
    public Builder setIdentity(String identity) {
376
      this.identity = identity;
×
377
      return this;
×
378
    }
379

380
    public WorkerOptions build() {
381
      return new WorkerOptions(
1✔
382
          maxWorkerActivitiesPerSecond,
383
          maxConcurrentActivityExecutionSize,
384
          maxConcurrentWorkflowTaskExecutionSize,
385
          maxConcurrentLocalActivityExecutionSize,
386
          maxTaskQueueActivitiesPerSecond,
387
          maxConcurrentWorkflowTaskPollers,
388
          maxConcurrentActivityTaskPollers,
389
          localActivityWorkerOnly,
390
          defaultDeadlockDetectionTimeout,
391
          maxHeartbeatThrottleInterval,
392
          defaultHeartbeatThrottleInterval,
393
          stickyQueueScheduleToStartTimeout,
394
          disableEagerExecution,
395
          useBuildIdForVersioning,
396
          buildId,
397
          stickyTaskQueueDrainTimeout,
398
          identity);
399
    }
400

401
    public WorkerOptions validateAndBuildWithDefaults() {
402
      Preconditions.checkState(
1✔
403
          maxWorkerActivitiesPerSecond >= 0, "negative maxActivitiesPerSecond");
404
      Preconditions.checkState(
1✔
405
          maxConcurrentActivityExecutionSize >= 0, "negative maxConcurrentActivityExecutionSize");
406
      Preconditions.checkState(
1✔
407
          maxConcurrentWorkflowTaskExecutionSize >= 0,
408
          "negative maxConcurrentWorkflowTaskExecutionSize");
409
      Preconditions.checkState(
1✔
410
          maxConcurrentLocalActivityExecutionSize >= 0,
411
          "negative maxConcurrentLocalActivityExecutionSize");
412
      Preconditions.checkState(
1✔
413
          maxTaskQueueActivitiesPerSecond >= 0, "negative taskQueueActivitiesPerSecond");
414
      Preconditions.checkState(
1✔
415
          maxConcurrentWorkflowTaskPollers >= 0, "negative maxConcurrentWorkflowTaskPollers");
416
      Preconditions.checkState(
1✔
417
          maxConcurrentActivityTaskPollers >= 0, "negative maxConcurrentActivityTaskPollers");
418
      Preconditions.checkState(
1✔
419
          defaultDeadlockDetectionTimeout >= 0, "negative defaultDeadlockDetectionTimeout");
420
      Preconditions.checkState(
1✔
421
          stickyQueueScheduleToStartTimeout == null
422
              || !stickyQueueScheduleToStartTimeout.isNegative(),
1✔
423
          "negative stickyQueueScheduleToStartTimeout");
424
      if (useBuildIdForVersioning) {
1✔
425
        Preconditions.checkState(
1✔
426
            buildId != null && !buildId.isEmpty(),
1✔
427
            "buildId must be set non-empty if useBuildIdForVersioning is set true");
428
      }
429
      Preconditions.checkState(
1✔
430
          stickyTaskQueueDrainTimeout == null || !stickyTaskQueueDrainTimeout.isNegative(),
1✔
431
          "negative stickyTaskQueueDrainTimeout");
432

433
      return new WorkerOptions(
1✔
434
          maxWorkerActivitiesPerSecond,
435
          maxConcurrentActivityExecutionSize == 0
1✔
436
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE
1✔
437
              : maxConcurrentActivityExecutionSize,
1✔
438
          maxConcurrentWorkflowTaskExecutionSize == 0
1✔
439
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE
1✔
440
              : maxConcurrentWorkflowTaskExecutionSize,
1✔
441
          maxConcurrentLocalActivityExecutionSize == 0
1✔
442
              ? DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE
1✔
443
              : maxConcurrentLocalActivityExecutionSize,
1✔
444
          maxTaskQueueActivitiesPerSecond,
445
          maxConcurrentWorkflowTaskPollers == 0
1✔
446
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS
1✔
447
              : maxConcurrentWorkflowTaskPollers,
1✔
448
          maxConcurrentActivityTaskPollers == 0
1✔
449
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS
1✔
450
              : maxConcurrentActivityTaskPollers,
1✔
451
          localActivityWorkerOnly,
452
          defaultDeadlockDetectionTimeout == 0
1✔
453
              ? DEFAULT_DEADLOCK_DETECTION_TIMEOUT
1✔
454
              : defaultDeadlockDetectionTimeout,
1✔
455
          maxHeartbeatThrottleInterval == null || maxHeartbeatThrottleInterval.isZero()
1✔
456
              ? DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL
1✔
457
              : maxHeartbeatThrottleInterval,
1✔
458
          defaultHeartbeatThrottleInterval == null || defaultHeartbeatThrottleInterval.isZero()
1✔
459
              ? DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL
1✔
460
              : defaultHeartbeatThrottleInterval,
1✔
461
          stickyQueueScheduleToStartTimeout == null
1✔
462
              ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
1✔
463
              : stickyQueueScheduleToStartTimeout,
1✔
464
          disableEagerExecution,
465
          useBuildIdForVersioning,
466
          buildId,
467
          stickyTaskQueueDrainTimeout == null
1✔
468
              ? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
1✔
469
              : stickyTaskQueueDrainTimeout,
1✔
470
          identity);
471
    }
472
  }
473

474
  private final double maxWorkerActivitiesPerSecond;
475
  private final int maxConcurrentActivityExecutionSize;
476
  private final int maxConcurrentWorkflowTaskExecutionSize;
477
  private final int maxConcurrentLocalActivityExecutionSize;
478
  private final double maxTaskQueueActivitiesPerSecond;
479
  private final int maxConcurrentWorkflowTaskPollers;
480
  private final int maxConcurrentActivityTaskPollers;
481
  private final boolean localActivityWorkerOnly;
482
  private final long defaultDeadlockDetectionTimeout;
483
  private final Duration maxHeartbeatThrottleInterval;
484
  private final Duration defaultHeartbeatThrottleInterval;
485
  private final @Nonnull Duration stickyQueueScheduleToStartTimeout;
486
  private final boolean disableEagerExecution;
487
  private final boolean useBuildIdForVersioning;
488
  private final String buildId;
489
  private final Duration stickyTaskQueueDrainTimeout;
490
  private final String identity;
491

492
  private WorkerOptions(
493
      double maxWorkerActivitiesPerSecond,
494
      int maxConcurrentActivityExecutionSize,
495
      int maxConcurrentWorkflowExecutionSize,
496
      int maxConcurrentLocalActivityExecutionSize,
497
      double maxTaskQueueActivitiesPerSecond,
498
      int workflowPollThreadCount,
499
      int activityPollThreadCount,
500
      boolean localActivityWorkerOnly,
501
      long defaultDeadlockDetectionTimeout,
502
      Duration maxHeartbeatThrottleInterval,
503
      Duration defaultHeartbeatThrottleInterval,
504
      @Nonnull Duration stickyQueueScheduleToStartTimeout,
505
      boolean disableEagerExecution,
506
      boolean useBuildIdForVersioning,
507
      String buildId,
508
      Duration stickyTaskQueueDrainTimeout,
509
      String identity) {
1✔
510
    this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
511
    this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
512
    this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowExecutionSize;
1✔
513
    this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
514
    this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
515
    this.maxConcurrentWorkflowTaskPollers = workflowPollThreadCount;
1✔
516
    this.maxConcurrentActivityTaskPollers = activityPollThreadCount;
1✔
517
    this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
518
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
519
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
520
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
521
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
522
    this.disableEagerExecution = disableEagerExecution;
1✔
523
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
524
    this.buildId = buildId;
1✔
525
    this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
526
    this.identity = identity;
1✔
527
  }
1✔
528

529
  public double getMaxWorkerActivitiesPerSecond() {
530
    return maxWorkerActivitiesPerSecond;
1✔
531
  }
532

533
  public int getMaxConcurrentActivityExecutionSize() {
534
    return maxConcurrentActivityExecutionSize;
1✔
535
  }
536

537
  public int getMaxConcurrentWorkflowTaskExecutionSize() {
538
    return maxConcurrentWorkflowTaskExecutionSize;
1✔
539
  }
540

541
  public int getMaxConcurrentLocalActivityExecutionSize() {
542
    return maxConcurrentLocalActivityExecutionSize;
1✔
543
  }
544

545
  public double getMaxTaskQueueActivitiesPerSecond() {
546
    return maxTaskQueueActivitiesPerSecond;
1✔
547
  }
548

549
  /**
550
   * @deprecated use {@link #getMaxConcurrentWorkflowTaskPollers}
551
   */
552
  @Deprecated
553
  public int getWorkflowPollThreadCount() {
554
    return getMaxConcurrentWorkflowTaskPollers();
×
555
  }
556

557
  public int getMaxConcurrentWorkflowTaskPollers() {
558
    return maxConcurrentWorkflowTaskPollers;
1✔
559
  }
560

561
  /**
562
   * @deprecated use {@link #getMaxConcurrentActivityTaskPollers}
563
   */
564
  @Deprecated
565
  public int getActivityPollThreadCount() {
566
    return getMaxConcurrentActivityTaskPollers();
×
567
  }
568

569
  public int getMaxConcurrentActivityTaskPollers() {
570
    return maxConcurrentActivityTaskPollers;
1✔
571
  }
572

573
  public long getDefaultDeadlockDetectionTimeout() {
574
    return defaultDeadlockDetectionTimeout;
1✔
575
  }
576

577
  public boolean isLocalActivityWorkerOnly() {
578
    return localActivityWorkerOnly;
1✔
579
  }
580

581
  public Duration getMaxHeartbeatThrottleInterval() {
582
    return maxHeartbeatThrottleInterval;
1✔
583
  }
584

585
  public Duration getDefaultHeartbeatThrottleInterval() {
586
    return defaultHeartbeatThrottleInterval;
1✔
587
  }
588

589
  @Nonnull
590
  public Duration getStickyQueueScheduleToStartTimeout() {
591
    return stickyQueueScheduleToStartTimeout;
1✔
592
  }
593

594
  public boolean isEagerExecutionDisabled() {
595
    return disableEagerExecution;
1✔
596
  }
597

598
  public boolean isUsingBuildIdForVersioning() {
599
    return useBuildIdForVersioning;
1✔
600
  }
601

602
  public String getBuildId() {
603
    return buildId;
1✔
604
  }
605

606
  public Duration getStickyTaskQueueDrainTimeout() {
607
    return stickyTaskQueueDrainTimeout;
1✔
608
  }
609

610
  @Nullable
611
  public String getIdentity() {
612
    return identity;
1✔
613
  }
614

615
  @Override
616
  public boolean equals(Object o) {
617
    if (this == o) return true;
1✔
618
    if (o == null || getClass() != o.getClass()) return false;
1✔
619
    WorkerOptions that = (WorkerOptions) o;
1✔
620
    return compare(that.maxWorkerActivitiesPerSecond, maxWorkerActivitiesPerSecond) == 0
1✔
621
        && maxConcurrentActivityExecutionSize == that.maxConcurrentActivityExecutionSize
622
        && maxConcurrentWorkflowTaskExecutionSize == that.maxConcurrentWorkflowTaskExecutionSize
623
        && maxConcurrentLocalActivityExecutionSize == that.maxConcurrentLocalActivityExecutionSize
624
        && compare(that.maxTaskQueueActivitiesPerSecond, maxTaskQueueActivitiesPerSecond) == 0
1✔
625
        && maxConcurrentWorkflowTaskPollers == that.maxConcurrentWorkflowTaskPollers
626
        && maxConcurrentActivityTaskPollers == that.maxConcurrentActivityTaskPollers
627
        && localActivityWorkerOnly == that.localActivityWorkerOnly
628
        && defaultDeadlockDetectionTimeout == that.defaultDeadlockDetectionTimeout
629
        && Objects.equals(maxHeartbeatThrottleInterval, that.maxHeartbeatThrottleInterval)
1✔
630
        && Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
1✔
631
        && Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
1✔
632
        && disableEagerExecution == that.disableEagerExecution
633
        && useBuildIdForVersioning == that.useBuildIdForVersioning
634
        && Objects.equals(that.buildId, buildId)
1✔
635
        && Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
1✔
636
        && Objects.equals(identity, that.identity);
1✔
637
  }
638

639
  @Override
640
  public int hashCode() {
641
    return Objects.hash(
×
642
        maxWorkerActivitiesPerSecond,
×
643
        maxConcurrentActivityExecutionSize,
×
644
        maxConcurrentWorkflowTaskExecutionSize,
×
645
        maxConcurrentLocalActivityExecutionSize,
×
UNCOV
646
        maxTaskQueueActivitiesPerSecond,
×
647
        maxConcurrentWorkflowTaskPollers,
×
648
        maxConcurrentActivityTaskPollers,
×
649
        localActivityWorkerOnly,
×
650
        defaultDeadlockDetectionTimeout,
×
651
        maxHeartbeatThrottleInterval,
652
        defaultHeartbeatThrottleInterval,
653
        stickyQueueScheduleToStartTimeout,
654
        disableEagerExecution,
×
655
        useBuildIdForVersioning,
×
656
        buildId,
657
        stickyTaskQueueDrainTimeout,
658
        identity);
659
  }
660

661
  @Override
662
  public String toString() {
663
    return "WorkerOptions{"
×
664
        + "maxWorkerActivitiesPerSecond="
665
        + maxWorkerActivitiesPerSecond
666
        + ", maxConcurrentActivityExecutionSize="
667
        + maxConcurrentActivityExecutionSize
668
        + ", maxConcurrentWorkflowTaskExecutionSize="
669
        + maxConcurrentWorkflowTaskExecutionSize
670
        + ", maxConcurrentLocalActivityExecutionSize="
671
        + maxConcurrentLocalActivityExecutionSize
672
        + ", maxTaskQueueActivitiesPerSecond="
673
        + maxTaskQueueActivitiesPerSecond
674
        + ", maxConcurrentWorkflowTaskPollers="
675
        + maxConcurrentWorkflowTaskPollers
676
        + ", maxConcurrentActivityTaskPollers="
677
        + maxConcurrentActivityTaskPollers
678
        + ", localActivityWorkerOnly="
679
        + localActivityWorkerOnly
680
        + ", defaultDeadlockDetectionTimeout="
681
        + defaultDeadlockDetectionTimeout
682
        + ", maxHeartbeatThrottleInterval="
683
        + maxHeartbeatThrottleInterval
684
        + ", defaultHeartbeatThrottleInterval="
685
        + defaultHeartbeatThrottleInterval
686
        + ", stickyQueueScheduleToStartTimeout="
687
        + stickyQueueScheduleToStartTimeout
688
        + ", disableEagerExecution="
689
        + disableEagerExecution
690
        + ", useBuildIdForVersioning="
691
        + useBuildIdForVersioning
692
        + ", buildId='"
693
        + buildId
694
        + ", stickyTaskQueueDrainTimeout='"
695
        + stickyTaskQueueDrainTimeout
696
        + ", identity="
697
        + identity
698
        + '}';
699
  }
700
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc