Skip to content

Commit

Permalink
Merge pull request #534 from jglick/FlowExecutionList-JENKINS-67164
Browse files Browse the repository at this point in the history
Defer being “ready to run” until `StepExecution.onResume`s complete
  • Loading branch information
jglick authored Jun 3, 2022
2 parents cd48bb9 + 3708876 commit 7bc717e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.332.x</artifactId>
<version>1289.v5c4b_1c43511b_</version>
<version>1382.v7d694476f340</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand All @@ -89,6 +89,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>1162.va_1e49062a_00e</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ public class CpsFlowExecution extends FlowExecution implements BlockableResume {

boolean resumeBlocked = false;

/**
* Whether {@link CpsThreadGroup#isPaused} when loaded from disk.
* @see #loadProgramAsync
* @see #afterStepExecutionsResumed
*/
private transient boolean pausedWhenLoaded;

/** Subdirectory string where we store {@link FlowNode}s */
private String storageDir = null;

Expand Down Expand Up @@ -775,17 +782,8 @@ public void onSuccess(Unmarshaller u) {
try {
CpsThreadGroup g = (CpsThreadGroup) u.readObject();
result.set(g);
try {
if (g.isPaused()) {
owner.getListener().getLogger().println("Still paused");
} else {
owner.getListener().getLogger().println("Ready to run at " + new Date());
// In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
g.scheduleRun();
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
pausedWhenLoaded = g.isPaused();
g.pause();
} catch (Throwable t) {
onFailure(t);
} finally {
Expand Down Expand Up @@ -871,6 +869,28 @@ void croak(Throwable t) {
}
}

@Override protected void afterStepExecutionsResumed() {
runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {
@Override public void onSuccess(CpsThreadGroup g) {
try {
if (pausedWhenLoaded) {
owner.getListener().getLogger().println("Still paused");
} else {
owner.getListener().getLogger().println("Ready to run at " + new Date());
// In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
g.unpause();
g.saveProgramIfPossible(false); // ensure pausedWhenLoaded=false is persisted
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
}
@Override public void onFailure(Throwable t) {
LOGGER.log(Level.WARNING, "could not resume " + this, t);
}
});
}

/**
* Where we store {@link CpsThreadGroup}.
*/
Expand Down

0 comments on commit 7bc717e

Please sign in to comment.