From 01c20deae7dd5428186c1ec081dcc2b5ccafd954 Mon Sep 17 00:00:00 2001 From: Joshua Rodriguez Date: Tue, 14 Jan 2025 15:20:12 -0800 Subject: [PATCH] DAR-CORE-CWS: Observed multiple jobs running on worker configured to run at most 1. --- .../main/java/jpl/cws/engine/WorkerService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cws-engine-service/src/main/java/jpl/cws/engine/WorkerService.java b/cws-engine-service/src/main/java/jpl/cws/engine/WorkerService.java index cebb0c1a..333c54fc 100644 --- a/cws-engine-service/src/main/java/jpl/cws/engine/WorkerService.java +++ b/cws-engine-service/src/main/java/jpl/cws/engine/WorkerService.java @@ -724,6 +724,20 @@ public List> claimWithCounter(String limitToProcDefKey) { int queryLimit = Math.min(MaxNumForProcsOnWorker, workerMaxProcQueryLimit); + // Adjust queryLimitForProcSet to ensure total claimed won't exceed workerMaxProcQueryLimit + int totalPossibleClaims = 0; + for (Integer limit : queryLimitForProcSet.values()) { + totalPossibleClaims += limit; + } + if (totalPossibleClaims > queryLimit) { + // Scale down individual limits proportionally + double scaleFactor = (double)queryLimit / totalPossibleClaims; + for (Map.Entry entry : queryLimitForProcSet.entrySet()) { + int newLimit = Math.max(1, (int)(entry.getValue() * scaleFactor)); + queryLimitForProcSet.put(entry.getKey(), Math.min(newLimit, queryLimit)); + } + } + Map> claimRowData = schedulerDbService.claimHighestPriorityStartReq( workerId, currentCounts, queryLimitForProcSet, queryLimit); // pass list of procDefkey and a map of queryLimit per procDefKey