提交 a3fe9ae9 编写于 作者: S stephenconnolly

Make the slave availability strategy actually do stuff!

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9353 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c32b011d
package hudson.model;
import hudson.model.Slave.ComputerImpl;
import static hudson.model.SlaveAvailabilityStrategy.*;
import hudson.triggers.SafeTimerTask;
import java.util.Map;
import java.util.WeakHashMap;
/**
* Periodically checks the slaves and try to reconnect dead slaves.
*
......@@ -10,12 +14,25 @@ import hudson.triggers.SafeTimerTask;
*/
public class SlaveReconnectionWork extends SafeTimerTask {
protected void doRun() {
for(Slave s : Hudson.getInstance().getSlaves()) {
ComputerImpl c = s.getComputer();
if(c==null) // shouldn't happen, but let's be defensive
continue;
if(c.isOffline() && c.isStartSupported())
c.tryReconnect();
// use a weak hashmap
Map<Slave, Long> nextCheck = new WeakHashMap<Slave, Long>();
for (Slave s : Hudson.getInstance().getSlaves()) {
if (!nextCheck.containsKey(s) || System.currentTimeMillis() > nextCheck.get(s)) {
final Queue queue = Hudson.getInstance().getQueue();
boolean hasJob = false;
for (Executor exec: s.getComputer().getExecutors()) {
if (!exec.isIdle()) {
hasJob = true;
break;
}
}
// TODO get only the items from the queue that can apply to this slave
State state = new State(queue.getItems().length > 0, hasJob);
// at the moment I don't trust strategies to wait more than 60 minutes
// strategies need to wait at least one minute
final long waitInMins = Math.min(1, Math.max(60, s.getAvailabilityStrategy().check(s, state)));
nextCheck.put(s, System.currentTimeMillis() + 60 * 1000 * waitInMins);
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册