Skip to content

Commit

Permalink
Merge pull request #304 from Vlatombe/computeNext-remove-side-effect
Browse files Browse the repository at this point in the history
Do not unregister completed executions when iterating over `FlowExecutionList` to avoid unnecessary log warnings
  • Loading branch information
dwnusbaum authored Aug 28, 2023
2 parents a2ff520 + ca179a2 commit d9baddd
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.logging.Logger;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.LinearBlockHoppingScanner;
import org.jvnet.hudson.reactor.Milestone;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
Expand Down Expand Up @@ -80,7 +79,7 @@ public FlowExecutionList() {
*/
@Override
public Iterator<FlowExecution> iterator() {
return new AbstractIterator<FlowExecution>() {
return new AbstractIterator<>() {
final Iterator<FlowExecutionOwner> base = runningTasks.iterator();

@Override
Expand All @@ -89,9 +88,7 @@ protected FlowExecution computeNext() {
FlowExecutionOwner o = base.next();
try {
FlowExecution e = o.get();
if (e.isComplete()) {
unregister(o);
} else {
if (!e.isComplete()) {
return e;
}
} catch (Throwable e) {
Expand Down Expand Up @@ -208,13 +205,32 @@ public boolean isResumptionComplete() {
public static class ItemListenerImpl extends ItemListener {
@Override
public void onLoaded() {
FlowExecutionList list = FlowExecutionList.get();
for (final FlowExecution e : list) {
// The call to FlowExecutionOwner.get in the implementation of iterator() is sufficent to load the Pipeline.
FlowExecutionList.get().resume();
}
}

private void resume() {
boolean needSave = false;
for (var it = runningTasks.iterator(); it.hasNext(); ) {
var o = it.next();
try {
FlowExecution e = o.get();
LOGGER.log(Level.FINE, "Eagerly loaded {0}", e);
if (e.isComplete()) {
LOGGER.log(Level.FINE, "Unregistering completed " + o, e);
it.remove();
needSave = true;
}
} catch (IOException ex) {
LOGGER.log(Level.FINE, "Failed to load " + o + ". Unregistering", ex);
it.remove();
needSave = true;
}
list.resumptionComplete = true;
}
if (needSave) {
saveLater();
}
resumptionComplete = true;
}

/**
Expand Down

0 comments on commit d9baddd

Please sign in to comment.