forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLiveGraphLifecycle.java
More file actions
50 lines (44 loc) · 1.75 KB
/
LiveGraphLifecycle.java
File metadata and controls
50 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package io.jenkins.plugins.pipelinegraphview.livestate;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Creates {@link LiveGraphState} entries at execution start / resume and evicts them on
* completion. Without this, entries are still created lazily by {@link LiveGraphPopulator}
* on first {@code onNewHead}, but {@code onResumed} guarantees the catch-up scan happens
* once up-front rather than at the first event after restart.
*/
@Extension
public class LiveGraphLifecycle extends FlowExecutionListener {
private static final Logger logger = LoggerFactory.getLogger(LiveGraphLifecycle.class);
@Override
public void onRunning(@NonNull FlowExecution execution) {
try {
LiveGraphRegistry.get().getOrCreate(execution);
} catch (Throwable t) {
logger.warn("pipeline-graph-view live state onRunning failed", t);
}
}
@Override
public void onResumed(@NonNull FlowExecution execution) {
try {
LiveGraphState state = LiveGraphRegistry.get().getOrCreate(execution);
if (state != null) {
LiveGraphPopulator.catchUp(execution, state);
}
} catch (Throwable t) {
logger.warn("pipeline-graph-view live state onResumed failed", t);
}
}
@Override
public void onCompleted(@NonNull FlowExecution execution) {
try {
LiveGraphRegistry.get().remove(execution);
} catch (Throwable t) {
logger.warn("pipeline-graph-view live state onCompleted failed", t);
}
}
}