3434import java .util .concurrent .RejectedExecutionException ;
3535import java .util .concurrent .TimeUnit ;
3636import java .util .concurrent .atomic .AtomicBoolean ;
37- import java .util .concurrent .atomic .AtomicInteger ;
3837import java .util .function .Supplier ;
3938import javax .annotation .Nonnull ;
4039import javax .annotation .Nullable ;
@@ -62,10 +61,9 @@ final class WorkflowWorker implements SuspendableWorker {
6261 private final TrackingSlotSupplier <WorkflowSlotInfo > slotSupplier ;
6362 private volatile Supplier <WorkerHeartbeat > heartbeatSupplier ;
6463 private final String workerInstanceKey ;
65- private final List <TaskQueueType > activeTaskQueueTypes ;
64+ private final Supplier < List <TaskQueueType >> activeTaskQueueTypesSupplier ;
6665
67- private final AtomicInteger totalProcessedTasks = new AtomicInteger ();
68- private final AtomicInteger totalFailedTasks = new AtomicInteger ();
66+ private final TaskCounter taskCounter = new TaskCounter ();
6967 private final PollerTracker pollerTracker = new PollerTracker ();
7068 private final PollerTracker stickyPollerTracker = new PollerTracker ();
7169 private final AtomicBoolean serverSupportsAutoscaling ;
@@ -83,7 +81,7 @@ public WorkflowWorker(
8381 @ Nonnull String namespace ,
8482 @ Nonnull String taskQueue ,
8583 @ Nonnull String workerInstanceKey ,
86- @ Nonnull List <TaskQueueType > activeTaskQueueTypes ,
84+ @ Nonnull Supplier < List <TaskQueueType >> activeTaskQueueTypesSupplier ,
8785 @ Nullable String stickyTaskQueueName ,
8886 @ Nonnull SingleWorkerOptions options ,
8987 @ Nonnull WorkflowRunLockManager runLocks ,
@@ -96,7 +94,7 @@ public WorkflowWorker(
9694 this .namespace = Objects .requireNonNull (namespace );
9795 this .taskQueue = Objects .requireNonNull (taskQueue );
9896 this .workerInstanceKey = Objects .requireNonNull (workerInstanceKey );
99- this .activeTaskQueueTypes = Objects .requireNonNull (activeTaskQueueTypes );
97+ this .activeTaskQueueTypesSupplier = Objects .requireNonNull (activeTaskQueueTypesSupplier );
10098 this .options = Objects .requireNonNull (options );
10199 this .stickyTaskQueueName = stickyTaskQueueName ;
102100 this .pollerOptions = getPollerOptions (options );
@@ -245,7 +243,7 @@ public CompletableFuture<Void> shutdown(ShutdownManager shutdownManager, boolean
245243 .setTaskQueue (taskQueue )
246244 .setWorkerInstanceKey (workerInstanceKey )
247245 .setReason (GRACEFUL_SHUTDOWN_MESSAGE )
248- .addAllTaskQueueTypes (activeTaskQueueTypes );
246+ .addAllTaskQueueTypes (activeTaskQueueTypesSupplier . get () );
249247 if (stickyTaskQueueName != null ) {
250248 shutdownReq .setStickyTaskQueue (stickyTaskQueueName );
251249 }
@@ -382,12 +380,8 @@ public String getStickyTaskQueueName() {
382380 return stickyTaskQueueName ;
383381 }
384382
385- public AtomicInteger getTotalProcessedTasks () {
386- return totalProcessedTasks ;
387- }
388-
389- public AtomicInteger getTotalFailedTasks () {
390- return totalFailedTasks ;
383+ public TaskCounter getTaskCounter () {
384+ return taskCounter ;
391385 }
392386
393387 public PollerOptions getPollerOptions () {
@@ -613,9 +607,9 @@ public void handle(WorkflowTask task) throws Exception {
613607 MDC .remove (LoggerTag .WORKFLOW_TYPE );
614608 MDC .remove (LoggerTag .RUN_ID );
615609
616- totalProcessedTasks . incrementAndGet ();
610+ taskCounter . recordProcessed ();
617611 if (taskProcessingFailed ) {
618- totalFailedTasks . incrementAndGet ();
612+ taskCounter . recordFailed ();
619613 }
620614
621615 if (locked ) {
0 commit comments