Skip to content

Commit

Permalink
Implementing FlowExecutionOwner.getExternalizableId
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jan 8, 2025
1 parent 90f02a2 commit d38f23c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM: -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/370 -->
<version>1348.vb_a_2c2a_42fd3c</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,12 @@ public boolean hasAllowKill() {

private static final Map<String,WorkflowRun> LOADING_RUNS = new HashMap<>();

private String key() {
return getParent().getFullName() + '/' + getId();
}

/** Hack to allow {@link #execution} to use an {@link Owner} referring to this run, even when it has not yet been loaded. */
@Override public void reload() throws IOException {
LOGGER.fine(() -> "Adding " + key() + " to LOADING_RUNS");
LOGGER.fine(() -> "Adding " + getExternalizableId() + " to LOADING_RUNS");
synchronized (LOADING_RUNS) {
LOADING_RUNS.put(key(), this);
LOADING_RUNS.put(getExternalizableId(), this);
}

// super.reload() forces result to be FAILURE, so working around that
Expand Down Expand Up @@ -613,9 +610,9 @@ private String key() {
}
} finally { // Ensure the run is ALWAYS removed from loading even if something failed, so threads awaken.
checkouts(null); // only for diagnostics
LOGGER.fine(() -> "Removing " + key() + " from LOADING_RUNS");
LOGGER.fine(() -> "Removing " + getExternalizableId() + " from LOADING_RUNS");
synchronized (LOADING_RUNS) {
LOADING_RUNS.remove(key()); // or could just make the value type be WeakReference<WorkflowRun>
LOADING_RUNS.remove(getExternalizableId()); // or could just make the value type be WeakReference<WorkflowRun>
LOADING_RUNS.notifyAll();
}
}
Expand Down Expand Up @@ -944,14 +941,11 @@ private static final class Owner extends FlowExecutionOwner {
id = run.getId();
this.run = run;
}
private String key() {
return job + '/' + id;
}
private @NonNull WorkflowRun run() throws IOException {
if (run==null) {
WorkflowRun candidate;
synchronized (LOADING_RUNS) {
candidate = LOADING_RUNS.get(key());
candidate = LOADING_RUNS.get(getExternalizableId());
}
if (candidate != null && candidate.getParent().getFullName().equals(job) && candidate.getId().equals(id)) {
run = candidate;
Expand Down Expand Up @@ -982,8 +976,8 @@ private String key() {
WorkflowRun r = run();
synchronized (LOADING_RUNS) {
int count = 5;
while (r.execution == null && LOADING_RUNS.containsKey(key()) && count-- > 0) {
try (WithThreadName naming = new WithThreadName(": waiting for " + key())) {
while (r.execution == null && LOADING_RUNS.containsKey(getExternalizableId()) && count-- > 0) {

Check warning on line 979 in src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 979 is only partially covered, 5 branches are missing
try (WithThreadName naming = new WithThreadName(": waiting for " + getExternalizableId())) {

Check warning on line 980 in src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 980 is not covered by tests
LOADING_RUNS.wait(/* 1m */60_000);
} catch (InterruptedException x) {
LOGGER.log(Level.WARNING, "failed to wait for " + r + " to be loaded", x);
Expand Down Expand Up @@ -1020,13 +1014,16 @@ private String key() {
@Override public String getUrl() throws IOException {
return run().getUrl();
}
@Override public @NonNull String getExternalizableId() {
return job + '#' + id;
}

@NonNull
@Override public TaskListener getListener() throws IOException {
return run().getListener();
}
@Override public String toString() {
return "Owner[" + key() + ":" + run + "]";
return getExternalizableId();
}

@Override
Expand Down

0 comments on commit d38f23c

Please sign in to comment.