Stop workflow in any status (#17271)

Workflows can now be cancelled when not started or enqueued.
Also displaying the stop option when selecting all.

We got the case of a client that did an infinite loop. So he had a lot
of workflows to stop. Supporting select all would have avoid him to wait
for 4 hours so we process the runs throttled. This is not something that
is supposed to happen often so I did not see the point of refactoring
the endpoint. But I wanted the users to have this option just in case
This commit is contained in:
Thomas Trompette
2026-01-20 17:38:39 +01:00
committed by GitHub
parent e40130f575
commit 799b08e1f2
7 changed files with 82 additions and 16 deletions
@@ -80,6 +80,13 @@ export class RunWorkflowJob {
workspaceId,
});
if (
workflowRun.status !== WorkflowRunStatus.ENQUEUED &&
workflowRun.status !== WorkflowRunStatus.NOT_STARTED
) {
return;
}
const workflowVersion =
await this.workflowCommonWorkspaceService.getWorkflowVersionOrFail({
workspaceId,
@@ -156,7 +156,10 @@ export class WorkflowRunWorkspaceService {
workflowRunToUpdate.status !== WorkflowRunStatus.ENQUEUED &&
workflowRunToUpdate.status !== WorkflowRunStatus.NOT_STARTED
) {
return;
throw new WorkflowRunException(
'Workflow run is not enqueued or not started',
WorkflowRunExceptionCode.INVALID_OPERATION,
);
}
const partialUpdate = {
@@ -200,12 +200,18 @@ export class WorkflowRunnerWorkspaceService {
workspaceId,
});
if (workflowRun.status !== WorkflowRunStatus.RUNNING) {
const stoppableStatuses = [
WorkflowRunStatus.NOT_STARTED,
WorkflowRunStatus.ENQUEUED,
WorkflowRunStatus.RUNNING,
];
if (!stoppableStatuses.includes(workflowRun.status)) {
throw new WorkflowRunException(
'Workflow run is not running',
'Workflow run cannot be stopped',
WorkflowRunExceptionCode.INVALID_OPERATION,
{
userFriendlyMessage: msg`Workflow run is not running`,
userFriendlyMessage: msg`Workflow run cannot be stopped in its current status`,
},
);
}