Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.jenkinsci.plugins.workflow.FilePathUtils;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.log.OutputStreamTaskListener;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
Expand Down Expand Up @@ -765,6 +766,9 @@
@Extension public static final class AgentReconnectionListener extends ComputerListener {

@Override public void onOffline(Computer c, OfflineCause cause) {
if (!USE_WATCHING) {
return;
}
if (Jenkins.get().isTerminating()) {
LOGGER.fine(() -> "Skipping check on " + c.getName() + " during shutdown");
return;
Expand All @@ -773,6 +777,9 @@
}

@Override public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
if (!USE_WATCHING) {
return;
}
if (!FlowExecutionList.get().isResumptionComplete()) {
LOGGER.fine(() -> "Skipping check on " + c.getName() + " before builds are ready");
return;
Expand All @@ -782,12 +789,33 @@

private void check(Computer c) {
String name = c.getName();
StepExecution.acceptAll(Execution.class, exec -> {
if (exec.watching && exec.node.equals(name)) {
LOGGER.fine(() -> "Online/offline event on " + name + ", checking current status of " + exec.remote + " soon");
threadPool().schedule(exec::check, 15, TimeUnit.SECONDS);
// More efficient than StepExecution.acceptAll(Execution.class, exec -> …):
for (var executor : c.getExecutors()) {
var executable = executor.getCurrentExecutable();
if (executable != null && executable.getParentExecutable() instanceof FlowExecutionOwner.Executable feoe) {

Check warning on line 795 in src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 795 is only partially covered, one branch is missing
var feo = feoe.asFlowExecutionOwner();
if (feo != null) {

Check warning on line 797 in src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 797 is only partially covered, one branch is missing
try {
var fe = feo.get();
var executionsFuture = fe.getCurrentExecutions(true);
executionsFuture.addListener(() -> {
try {
for (var execution : executionsFuture.get()) {
if (execution instanceof Execution exec && exec.watching && exec.node.equals(name)) {

Check warning on line 804 in src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 804 is only partially covered, 2 branches are missing
LOGGER.fine(() -> "Online/offline event on " + name + ", checking current status of " + exec.remote + " soon");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ignore WS)

threadPool().schedule(exec::check, 15, TimeUnit.SECONDS);
}
}
} catch (Exception x) {
LOGGER.log(Level.WARNING, "could not inspect " + fe, x);

Check warning on line 810 in src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 809-810 are not covered by tests
}
}, Runnable::run);
} catch (IOException x) {
LOGGER.log(Level.WARNING, "could not inspect " + feo, x);

Check warning on line 814 in src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 813-814 are not covered by tests
}
}
}
});
}
}

}
Expand Down
Loading