mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-18 06:22:29 +00:00
better to have the demand start utility method in computer... it keeps the retention strategies simpler
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9446 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
c71690b7ca
commit
db07f253fc
2 files changed
+26
-23
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package hudson.model;
|
||||
|
||||
import hudson.EnvVars;
|
||||
import hudson.Util;
|
||||
import hudson.slaves.ComputerLauncher;
|
||||
import hudson.slaves.RetentionStrategy;
|
||||
import hudson.node_monitors.NodeMonitor;
|
||||
@@ -280,6 +281,17 @@ public abstract class Computer extends AbstractModelObject {
|
||||
return firstIdle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time when this computer first became in demand.
|
||||
*/
|
||||
public final long getDemandStartMilliseconds() {
|
||||
long firstDemand = Long.MAX_VALUE;
|
||||
for (Queue.Item item : Hudson.getInstance().getQueue().getBuildableItems(this)) {
|
||||
firstDemand = Math.min(item.buildableStartMilliseconds, firstDemand);
|
||||
}
|
||||
return firstDemand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link Executor} to kill excessive executors from this computer.
|
||||
*/
|
||||
|
||||
@@ -149,30 +149,21 @@ public abstract class RetentionStrategy<T extends Computer> implements Describab
|
||||
*/
|
||||
public synchronized long check(SlaveComputer c) {
|
||||
if (c.isOffline()) {
|
||||
final Queue queue = Hudson.getInstance().getQueue();
|
||||
for (Queue.Item item : queue.getBuildableItems(c)) {
|
||||
final long demandMilliseconds = System.currentTimeMillis() - item.buildableStartMilliseconds;
|
||||
if (demandMilliseconds >
|
||||
TimeUnit.MILLISECONDS.convert(inDemandDelay, TimeUnit.MINUTES)) {
|
||||
// we've been in demand for long enough
|
||||
logger.log(Level.INFO, "Launching computer {0} as it has been in demand for {1}",
|
||||
new Object[]{c.getNode().getNodeName(), Util.getTimeSpanString(demandMilliseconds)});
|
||||
if (c.isLaunchSupported())
|
||||
c.launch();
|
||||
|
||||
break;
|
||||
}
|
||||
final long demandMilliseconds = System.currentTimeMillis() - c.getDemandStartMilliseconds();
|
||||
if (demandMilliseconds > TimeUnit.MILLISECONDS.convert(inDemandDelay, TimeUnit.MINUTES)) {
|
||||
// we've been in demand for long enough
|
||||
logger.log(Level.INFO, "Launching computer {0} as it has been in demand for {1}",
|
||||
new Object[]{c.getNode().getNodeName(), Util.getTimeSpanString(demandMilliseconds)});
|
||||
if (c.isLaunchSupported())
|
||||
c.launch();
|
||||
}
|
||||
} else {
|
||||
if (c.isIdle()) {
|
||||
final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds();
|
||||
if (idleMilliseconds >
|
||||
TimeUnit.MILLISECONDS.convert(inDemandDelay, TimeUnit.MINUTES)) {
|
||||
// we've been idle for long enough
|
||||
logger.log(Level.INFO, "Disconnecting computer {0} as it has been idle for {1}",
|
||||
new Object[]{c.getNode().getNodeName(), Util.getTimeSpanString(idleMilliseconds)});
|
||||
c.disconnect();
|
||||
}
|
||||
} else if (c.isIdle()) {
|
||||
final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds();
|
||||
if (idleMilliseconds > TimeUnit.MILLISECONDS.convert(inDemandDelay, TimeUnit.MINUTES)) {
|
||||
// we've been idle for long enough
|
||||
logger.log(Level.INFO, "Disconnecting computer {0} as it has been idle for {1}",
|
||||
new Object[]{c.getNode().getNodeName(), Util.getTimeSpanString(idleMilliseconds)});
|
||||
c.disconnect();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user