Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ComputerListener#onIdle #9673

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
Expand All @@ -114,6 +115,7 @@
import jenkins.util.ErrorLoggingExecutorService;
import jenkins.util.Listeners;
import jenkins.util.SystemProperties;
import jenkins.util.Timer;
import jenkins.widgets.HasWidgets;
import net.jcip.annotations.GuardedBy;
import org.jenkins.ui.icon.Icon;
Expand Down Expand Up @@ -1093,6 +1095,7 @@ public final long getDemandStartMilliseconds() {
*/
protected void removeExecutor(final Executor e) {
final Runnable task = () -> {
jglick marked this conversation as resolved.
Show resolved Hide resolved
var idle = false;
synchronized (Computer.this) {
executors.remove(e);
oneOffExecutors.remove(e);
Expand All @@ -1102,8 +1105,13 @@ protected void removeExecutor(final Executor e) {
if (ciBase != null) { // TODO confirm safe to assume non-null and use getInstance()
ciBase.removeComputer(Computer.this);
}
} else {
idle = isIdle();
}
}
if (idle) {
Listeners.notify(ComputerListener.class, false, l -> l.onIdle(this));
}
};
if (!Queue.tryWithLock(task)) {
// JENKINS-28840 if we couldn't get the lock push the operation to a separate thread to avoid deadlocks
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/hudson/slaves/ComputerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ public void onTemporarilyOffline(Computer c, OfflineCause cause) {}
*/
public void onConfigurationChange() {}

/**
* Indicates that the computer has become idle.
*
* @since TODO
*/
public void onIdle(Computer c) {}

/**
* Registers this {@link ComputerListener} so that it will start receiving events.
*
Expand Down