Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ components:
- null
format: int64
description: Total duration in milliseconds (null if still running)
waitingForInput:
type: boolean
description: Whether the stage is waiting for user input
children:
type: array
items:
Expand Down
17 changes: 17 additions & 0 deletions src/main/frontend/common/components/status-icon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ describe("StatusIcon", () => {
expect(result.current).to.equal(0);
unmount();
});
it("should continue progress when waitingForInput is true", async () => {
const { result, unmount } = renderHook(() => {
return useStageProgress({
...mockStage,
state: Result.running,
startTimeMillis: now - 2_000,
previousTotalDurationMillis: 20_000,
waitingForInput: true,
});
});
expect(result.current).to.equal(10);
await act(() => vi.advanceTimersByTime(1_000));
expect(result.current).to.equal(15);
await act(() => vi.advanceTimersByTime(1_000));
expect(result.current).to.equal(20);
unmount();
});
});
describe("other states", function () {
for (const state in Result) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/frontend/common/components/status-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ export function resultToColor(result: Result, skeleton: boolean | undefined) {
return "jenkins-!-accent-color";
case "unstable":
return "jenkins-!-warning-color";
case "paused":
return "jenkins-!-accent-color";
default:
return "jenkins-!-skipped-color";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface StageInfo {

skeleton?: boolean;
pauseLiveTotal?: boolean;
waitingForInput?: boolean;
}

interface BaseNodeInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ private PipelineGraph createTree(PipelineGraphBuilderApi builder) {
// these are completely new representations.
List<PipelineStageInternal> stages = getPipelineNodes(builder);

// Set the builder on each stage so they can check for paused steps
if (builder instanceof PipelineStepBuilderApi) {
PipelineStepBuilderApi stepBuilder = (PipelineStepBuilderApi) builder;
stages.forEach(stage -> stage.setBuilder(stepBuilder));
}

// id => stage
Map<String, PipelineStageInternal> stageMap = stages.stream()
.collect(Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PipelineStage extends AbstractPipelineNode {
private final boolean placeholder;
final String agent;
private final String url;
public final boolean waitingForInput;

public PipelineStage(
String id,
Expand All @@ -32,8 +33,9 @@ public PipelineStage(
boolean placeholder,
TimingInfo timingInfo,
String agent,
String runUrl) {
super(id, name, state, type, title, timingInfo);
String runUrl,
boolean waitingForInput) {
super(id, name, waitingForInput ? PipelineState.PAUSED : state, type, title, timingInfo);
this.children = children;
this.seqContainerName = seqContainerName;
this.nextSibling = nextSibling;
Expand All @@ -42,6 +44,7 @@ public PipelineStage(
this.placeholder = placeholder;
this.agent = agent;
this.url = "/" + runUrl + URL_NAME + "?selected-node=" + id;
this.waitingForInput = waitingForInput;
}

public static class PipelineStageJsonProcessor extends AbstractPipelineNodeJsonProcessor {
Expand All @@ -64,6 +67,7 @@ public JSONObject processBean(Object bean, JsonConfig config) {
json.element("placeholder", stage.placeholder);
json.element("agent", stage.agent);
json.element("url", stage.url);
json.element("waitingForInput", stage.waitingForInput);
return json;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PipelineStageInternal {
private boolean synthetic;
private TimingInfo timingInfo;
private String agent;
private PipelineStepBuilderApi builder;

public PipelineStageInternal(
String id,
Expand Down Expand Up @@ -113,7 +114,43 @@ public void setAgent(String aAgent) {
this.agent = aAgent;
}

public void setBuilder(PipelineStepBuilderApi builder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be avoided by doing the refactoring mentioned in PipelineGraphApi comment and then you could just pass the builder in the constructor (or another constructor) as I'd prefer not to be mutating state

this.builder = builder;
}

/**
* Checks if this stage or any of its children are waiting for input.
* A stage is waiting for input if any of its steps have a non-null inputStep
* and the step state is PAUSED.
*/
private boolean isWaitingForInput(List<PipelineStage> children) {
// Check if any child stages are waiting for input
if (children != null && !children.isEmpty()) {
for (PipelineStage child : children) {
if (child.waitingForInput) {
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get some test coverage for this please?

A pipeline that sets an input step on it and validates the stage is now paused.

}
}
}

// Check steps for this stage
if (builder != null && id != null) {
List<FlowNodeWrapper> steps = builder.getStageSteps(id);
if (steps != null) {
for (FlowNodeWrapper step : steps) {
// Check if step has an input and is paused
if (step.getInputStep() != null && step.getStatus().state == BlueRun.BlueRunState.PAUSED) {
return true;
}
}
}
}

return false;
}

public PipelineStage toPipelineStage(List<PipelineStage> children, String runUrl) {
boolean waitingForInput = isWaitingForInput(children);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we only do this check if there is an InputAction attached to the WorkflowRun?

I think that should be optimisable so this check is only run over stages that could be waiting for input?

return new PipelineStage(
id,
name,
Expand All @@ -128,6 +165,7 @@ public PipelineStage toPipelineStage(List<PipelineStage> children, String runUrl
synthetic && name.equals(Messages.FlowNodeWrapper_noStage()),
timingInfo,
agent,
runUrl);
runUrl,
waitingForInput);
}
}
Loading