Skip to content

Commit 4b48432

Browse files
committed
Optimizing withExecution to only consider steps in the current build jenkinsci#180 (comment)
1 parent e022b6b commit 4b48432

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.jenkinsci.plugins.workflow.support.steps;
22

3+
import com.google.common.util.concurrent.FutureCallback;
4+
import com.google.common.util.concurrent.Futures;
5+
import com.google.common.util.concurrent.MoreExecutors;
36
import edu.umd.cs.findbugs.annotations.CheckForNull;
47
import edu.umd.cs.findbugs.annotations.NonNull;
58
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -65,6 +68,7 @@
6568
import org.jenkinsci.plugins.workflow.actions.LabelAction;
6669
import org.jenkinsci.plugins.workflow.actions.QueueItemAction;
6770
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
71+
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
6872
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
6973
import org.jenkinsci.plugins.workflow.graph.FlowNode;
7074
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
@@ -363,12 +367,22 @@ private Object readResolve() {
363367
* Instead we keep only {@link #context} and look up the execution as needed.
364368
*/
365369
private void withExecution(Consumer<ExecutorStepExecution> executionCallback) {
366-
StepExecution.applyAll(ExecutorStepExecution.class, execution -> {
367-
if (execution.getContext().equals(context)) {
368-
executionCallback.accept(execution);
369-
}
370-
return null;
371-
});
370+
try {
371+
Futures.addCallback(context.get(FlowExecution.class).getCurrentExecutions(false), new FutureCallback<List<StepExecution>>() {
372+
@Override public void onSuccess(List<StepExecution> result) {
373+
for (StepExecution execution : result) {
374+
if (execution instanceof ExecutorStepExecution && execution.getContext().equals(context)) {
375+
executionCallback.accept((ExecutorStepExecution) execution);
376+
}
377+
}
378+
}
379+
@Override public void onFailure(Throwable x) {
380+
LOGGER.log(Level.WARNING, null, x);
381+
}
382+
}, MoreExecutors.directExecutor());
383+
} catch (IOException | InterruptedException x) {
384+
LOGGER.log(Level.WARNING, null, x);
385+
}
372386
}
373387

374388
/**

0 commit comments

Comments
 (0)