mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
Lazy-load-friendly Job.getEstimatedDurationCandidates (#7998)
This commit is contained in:
1 parent
cb1d2dc532
commit
fe52887da2
6 files changed
+48
-3
No files matched your search
@@ -953,6 +953,11 @@ public abstract class AbstractProject<P extends AbstractProject<P, R>, R extends
|
||||
return buildMixIn.getNearestOldBuild(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<R> getEstimatedDurationCandidates() {
|
||||
return buildMixIn.getEstimatedDurationCandidates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type token for the corresponding build type.
|
||||
* The build class must have two constructors:
|
||||
|
||||
@@ -1013,6 +1013,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
|
||||
* Failing to find 3 of those, it will return up to 3 last unsuccessful builds.
|
||||
*
|
||||
* In any case it will not go more than 6 builds into the past to avoid costly build loading.
|
||||
* @see LazyBuildMixIn#getEstimatedDurationCandidates
|
||||
*/
|
||||
protected List<RunT> getEstimatedDurationCandidates() {
|
||||
List<RunT> candidates = new ArrayList<>(3);
|
||||
|
||||
@@ -34,6 +34,7 @@ import hudson.model.Item;
|
||||
import hudson.model.ItemGroup;
|
||||
import hudson.model.Job;
|
||||
import hudson.model.Queue;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.RunMap;
|
||||
import hudson.model.listeners.ItemListener;
|
||||
@@ -44,6 +45,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -265,6 +268,29 @@ public abstract class LazyBuildMixIn<JobT extends Job<JobT, RunT> & Queue.Task &
|
||||
return builds.search(n, AbstractLazyLoadRunMap.Direction.DESC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suitable for {@link Job#getEstimatedDurationCandidates}.
|
||||
* @since TODO
|
||||
*/
|
||||
public List<RunT> getEstimatedDurationCandidates() {
|
||||
var loadedBuilds = builds.getLoadedBuilds().values(); // reverse chronological order
|
||||
List<RunT> candidates = new ArrayList<>(3);
|
||||
for (Result threshold : List.of(Result.UNSTABLE, Result.FAILURE)) {
|
||||
for (RunT build : loadedBuilds) {
|
||||
if (!build.isBuilding()) {
|
||||
Result result = build.getResult();
|
||||
if (result != null && result.isBetterOrEqualTo(threshold)) {
|
||||
candidates.add(build);
|
||||
if (candidates.size() == 3) {
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suitable for {@link Job#createHistoryWidget}.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user