Skip to content

Commit

Permalink
[FIXED JENKINS-28446] - Calculate only tasks without assigned labels
Browse files Browse the repository at this point in the history
This implementation does not create new methods in API, hence it can be backported.

(cherry picked from commit 294ce77)
  • Loading branch information
oleg-nenashev authored and olivergondza committed Jun 8, 2015
1 parent 56fc386 commit ece651d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
Expand Up @@ -31,9 +31,11 @@
import hudson.model.Queue;
import hudson.model.Queue.Task;
import hudson.model.queue.SubTask;
import hudson.model.queue.Tasks;
import hudson.util.Iterators;

import java.util.Iterator;
import java.util.List;

/**
* {@link LoadStatistics} that track the "free roam" jobs (whose {@link Task#getAssignedLabel()} is null)
Expand Down Expand Up @@ -78,7 +80,20 @@ public int computeTotalExecutors() {

@Override
public int computeQueueLength() {
return Jenkins.getInstance().getQueue().countBuildableItemsFor(null);
final Jenkins j = Jenkins.getInstance();
if (j == null) { // Consider queue as empty when Jenkins is inactive
return 0;
}

int result = 0;
final List<Queue.BuildableItem> buildableItems = j.getQueue().getBuildableItems();
for (Queue.BuildableItem item : buildableItems) {
for (SubTask st : Tasks.getSubTasksOf(item.task)) {
if (item.getAssignedLabelFor(st) == null)
result++;
}
}
return result;
}

@Override
Expand Down

0 comments on commit ece651d

Please sign in to comment.