Skip to content

Commit 8abf217

Browse files
committed
fix: always provision a new node when exceeded capacity
1 parent 770451c commit 8abf217

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/main/java/dev/lsegal/jenkins/codebuilder/CodeBuilderCloud.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,9 @@ public synchronized Collection<PlannedNode> provision(Label label, int excessWor
369369
return list;
370370
}
371371

372-
long stillProvisioning = numStillProvisioning();
373-
long numToLaunch = Math.max(excessWorkload - stillProvisioning, 0);
374-
LOGGER.info("[CodeBuilder]: Provisioning {} nodes for label '{}' ({} already provisioning)", numToLaunch, labelName,
375-
stillProvisioning);
372+
LOGGER.info("[CodeBuilder]: Provisioning {} nodes for label '{}'", excessWorkload, labelName);
376373

377-
for (int i = 0; i < numToLaunch; i++) {
374+
for (int i = 0; i < excessWorkload; i++) {
378375
final String suffix = RandomStringUtils.randomAlphabetic(4);
379376
final String displayName = String.format("%s.cb-%s", projectName, suffix);
380377
final CodeBuilderCloud cloud = this;
@@ -391,19 +388,6 @@ public synchronized Collection<PlannedNode> provision(Label label, int excessWor
391388
return list;
392389
}
393390

394-
/**
395-
* Find the number of {@link CodeBuilderAgent} instances still connecting to
396-
* Jenkins host.
397-
*/
398-
private long numStillProvisioning() {
399-
return jenkins().getNodes().stream()
400-
// Get all `CodeBuilderAgent`s as `CodeBuilderAgent`s
401-
.filter(CodeBuilderAgent.class::isInstance).map(CodeBuilderAgent.class::cast)
402-
// Get all those that haven't succesfully launched yet (those for which 'launching' is 'supported')
403-
.filter(a -> a.getLauncher().isLaunchSupported())
404-
.count();
405-
}
406-
407391
/** {@inheritDoc} */
408392
@Override
409393
public boolean canProvision(Label label) {
@@ -455,7 +439,7 @@ public String getDefaultComputeType() {
455439
}
456440

457441
public boolean getDefaultTerminateAgent() {
458-
return DEFAULT_TERMINATE_AGENT;
442+
return DEFAULT_TERMINATE_AGENT;
459443
}
460444

461445
public ListBoxModel doFillCredentialsIdItems() {

0 commit comments

Comments
 (0)