Skip to content
Permalink
Browse files

[FIXED JENKINS-28446] - Calculate only tasks without assigned labels

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 May 18, 2015
1 parent 56fc386 commit ece651d4d0acc2a12bcc3c53780d67379a801e28
Showing with 16 additions and 1 deletion.
  1. +16 −1 core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
@@ -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)
@@ -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

0 comments on commit ece651d

Please sign in to comment.
You can’t perform that action at this time.