Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-28446] - Calculate only tasks without assigned labels
This implementation does not create new methods in API, hence it can be backported.
  • Loading branch information
oleg-nenashev committed May 18, 2015
1 parent 43b0662 commit 294ce77
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 294ce77

Please sign in to comment.