Skip to content

Commit 7bc717e

Browse files
authored
Merge pull request #534 from jglick/FlowExecutionList-JENKINS-67164
Defer being “ready to run” until `StepExecution.onResume`s complete
2 parents cd48bb9 + 3708876 commit 7bc717e

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<dependency>
7676
<groupId>io.jenkins.tools.bom</groupId>
7777
<artifactId>bom-2.332.x</artifactId>
78-
<version>1289.v5c4b_1c43511b_</version>
78+
<version>1382.v7d694476f340</version>
7979
<scope>import</scope>
8080
<type>pom</type>
8181
</dependency>
@@ -89,6 +89,7 @@
8989
<dependency>
9090
<groupId>org.jenkins-ci.plugins.workflow</groupId>
9191
<artifactId>workflow-api</artifactId>
92+
<version>1162.va_1e49062a_00e</version>
9293
</dependency>
9394
<dependency>
9495
<groupId>org.jenkins-ci.plugins.workflow</groupId>

src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ public class CpsFlowExecution extends FlowExecution implements BlockableResume {
277277

278278
boolean resumeBlocked = false;
279279

280+
/**
281+
* Whether {@link CpsThreadGroup#isPaused} when loaded from disk.
282+
* @see #loadProgramAsync
283+
* @see #afterStepExecutionsResumed
284+
*/
285+
private transient boolean pausedWhenLoaded;
286+
280287
/** Subdirectory string where we store {@link FlowNode}s */
281288
private String storageDir = null;
282289

@@ -775,17 +782,8 @@ public void onSuccess(Unmarshaller u) {
775782
try {
776783
CpsThreadGroup g = (CpsThreadGroup) u.readObject();
777784
result.set(g);
778-
try {
779-
if (g.isPaused()) {
780-
owner.getListener().getLogger().println("Still paused");
781-
} else {
782-
owner.getListener().getLogger().println("Ready to run at " + new Date());
783-
// In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
784-
g.scheduleRun();
785-
}
786-
} catch (IOException x) {
787-
LOGGER.log(Level.WARNING, null, x);
788-
}
785+
pausedWhenLoaded = g.isPaused();
786+
g.pause();
789787
} catch (Throwable t) {
790788
onFailure(t);
791789
} finally {
@@ -871,6 +869,28 @@ void croak(Throwable t) {
871869
}
872870
}
873871

872+
@Override protected void afterStepExecutionsResumed() {
873+
runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {
874+
@Override public void onSuccess(CpsThreadGroup g) {
875+
try {
876+
if (pausedWhenLoaded) {
877+
owner.getListener().getLogger().println("Still paused");
878+
} else {
879+
owner.getListener().getLogger().println("Ready to run at " + new Date());
880+
// In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
881+
g.unpause();
882+
g.saveProgramIfPossible(false); // ensure pausedWhenLoaded=false is persisted
883+
}
884+
} catch (IOException x) {
885+
LOGGER.log(Level.WARNING, null, x);
886+
}
887+
}
888+
@Override public void onFailure(Throwable t) {
889+
LOGGER.log(Level.WARNING, "could not resume " + this, t);
890+
}
891+
});
892+
}
893+
874894
/**
875895
* Where we store {@link CpsThreadGroup}.
876896
*/

0 commit comments

Comments
 (0)