Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java adopt-openjdk-8u242-b08
java adoptopenjdk-8.0.242+8.1
19 changes: 2 additions & 17 deletions src/main/java/dev/lsegal/jenkins/codebuilder/CodeBuilderAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,7 @@ public AbstractCloudComputer<CodeBuilderAgent> createComputer() {
/** {@inheritDoc} */
@Override
protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
listener.getLogger().println("[CodeBuilder]: Terminating agent: " + getDisplayName());

if (getLauncher() instanceof CodeBuilderLauncher) {
String buildId = ((CodeBuilderComputer) getComputer()).getBuildId();
if (StringUtils.isBlank(buildId)) {
return;
}

try {
LOGGER.info("[CodeBuilder]: Stopping build ID: {}", buildId);
cloud.getClient().stopBuild(new StopBuildRequest().withId(buildId));
} catch (ResourceNotFoundException e) {
// this is fine. really.
} catch (Exception e) {
LOGGER.error("[CodeBuilder]: Failed to stop build ID: {}", buildId, e);
}
}
LOGGER.info("[CodeBuilder]: Terminating agent: " + getDisplayName());
((CodeBuilderComputer) getComputer()).gracefulShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hudson.model.Executor;
import hudson.model.Queue;
import hudson.slaves.AbstractCloudComputer;
import hudson.slaves.OfflineCause;

/**
* CodeBuilderComputer class.
Expand Down Expand Up @@ -99,19 +100,15 @@ public String toString() {
return String.format("name: %s buildID: %s", getName(), getBuildId());
}

private void gracefulShutdown() {
protected void gracefulShutdown() {
setAcceptingTasks(false);

Future<Object> next = Computer.threadPoolForRemoting.submit(() -> {
LOGGER.info("[CodeBuilder]: [{}]: Terminating agent after task.", this);
try {
Thread.sleep(500);
CodeBuilderCloud.jenkins().removeNode(getNode());
} catch (Exception e) {
LOGGER.info("[CodeBuilder]: [{}]: Termination error: {}", this, e.getClass());
}
return null;
});
next.notify();
LOGGER.info("[CodeBuilder]: [{}]: Terminating agent after task.", this);
try {
Thread.sleep(500);
disconnect(new OfflineCause.IdleOfflineCause());
} catch (Exception e) {
LOGGER.info("[CodeBuilder]: [{}]: Termination error: {}", this, e.getClass());
}
}
}