Skip to content

Commit

Permalink
[JENKINS-23557] Add matrix child jobs in the fron of the queue
Browse files Browse the repository at this point in the history
MatrixConfiguration (children) will now inherit the place 
in the queue from the MatrixProject (parent)
  • Loading branch information
emsa23 committed Apr 25, 2015
1 parent fc9df24 commit 78ce5be
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Expand Up @@ -7,5 +7,7 @@ public interface PriorityConfigurationCallback extends DecisionLogger {
PriorityConfigurationCallback setPrioritySelection(int priority);

PriorityConfigurationCallback setPrioritySelection(int priority, int jobGroupId, PriorityStrategy reason);


PriorityConfigurationCallback setPrioritySelection(int priority, long sortAsInQueueSince, int jobGroupId, PriorityStrategy reason);

}
Expand Up @@ -21,8 +21,7 @@ PriorityConfigurationCallback getPriority(MatrixConfiguration matrixConfiguratio
priorityCallback.addDecisionLog(0, "Job is MatrixConfiguration [" + matrixProject.getName() + "] ...");
ItemInfo itemInfo = QueueItemCache.get().getItem(matrixProject.getName());
// Can be null (for example) at startup when the MatrixBuild got
// lost (was running at
// restart)
// lost (was running at restart)
if (itemInfo != null) {
priorityCallback.addDecisionLog(0, "MatrixProject found in cache, using priority from queue-item ["
+ itemInfo.getItemId() + "]");
Expand Down
Expand Up @@ -34,6 +34,11 @@ public PriorityConfigurationCallback setPrioritySelection(int priority) {
public PriorityConfigurationCallback addDecisionLog(int indent, String log) {
return this;
}

public PriorityConfigurationCallback setPrioritySelection(int priority, long sortAsInQueueSince,
int jobGroupId, PriorityStrategy reason) {
return this;
}
};

@Extension
Expand Down
Expand Up @@ -95,6 +95,11 @@ public PriorityConfigurationCallback setPrioritySelection(int priority) {
public PriorityConfigurationCallback addDecisionLog(int indent, String log) {
return this;
}

public PriorityConfigurationCallback setPrioritySelection(int priority, long sortAsInQueueSince,
int jobGroupId, PriorityStrategy reason) {
return this;
}
};

@Override
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java
Expand Up @@ -45,6 +45,8 @@ public class ItemInfo implements PriorityConfigurationCallback, DecisionLogger,
private int itemId;

private long inQueueSince;

private Long sortAsInQueueSince = null;

private int jobGroupId;

Expand Down Expand Up @@ -74,6 +76,14 @@ public PriorityConfigurationCallback setPrioritySelection(int priority, int jobG
return this;
}

public PriorityConfigurationCallback setPrioritySelection(int priority, long sortAsInQueueSince, int jobGroupId, PriorityStrategy reason) {
this.priority = priority;
this.sortAsInQueueSince = sortAsInQueueSince;
this.jobGroupId = jobGroupId;
this.priorityStrategy = reason;
return this;
}

public PriorityConfigurationCallback addDecisionLog(int indent, String log) {
this.decisionLog.add(String.format("%"+ ((indent + 1) * 2) + "s%s", "", log));
return this;
Expand Down Expand Up @@ -107,6 +117,13 @@ public long getInQueueSince() {
return inQueueSince;
}

public long getSortableInQueueSince() {
if(sortAsInQueueSince != null) {
return sortAsInQueueSince;
}
return inQueueSince;
}

public int getJobGroupId() {
return jobGroupId;
}
Expand All @@ -133,7 +150,7 @@ public ItemStatus getItemStatus() {

public int compareTo(ItemInfo o) {
if(this.getWeight() == o.getWeight()) {
if(this.getInQueueSince() == o.getInQueueSince()) {
if(this.getSortableInQueueSince() == o.getSortableInQueueSince()) {
return Integer.compare(this.getItemId(), o.getItemId());
}
return Long.compare(this.getInQueueSince(), o.getInQueueSince());
Expand Down

0 comments on commit 78ce5be

Please sign in to comment.