feat(API): Add running status query on the executions public api endpoint (#19205)

Co-authored-by: Konstantin Tieber <46342664+konstantintieber@users.noreply.github.com>
This commit is contained in:
Irénée
2025-09-11 13:03:23 +01:00
committed by GitHub
parent 03b865d4db
commit 3af4541391
8 changed files with 241 additions and 132 deletions

View File

@@ -114,19 +114,23 @@ export = {
return res.status(200).json({ data: [], nextCursor: null });
}
// get running workflows so we exclude them from the result
// get running executions so we exclude them from the result
const runningExecutionsIds = Container.get(ActiveExecutions)
.getActiveExecutions()
.map(({ id }) => id);
const filters = {
status,
limit,
lastId,
includeData,
workflowIds: workflowId ? [workflowId] : sharedWorkflowsIds,
excludedExecutionsIds: runningExecutionsIds,
};
const filters: Parameters<typeof ExecutionRepository.prototype.getExecutionsForPublicApi>[0] =
{
status,
limit,
lastId,
includeData,
workflowIds: workflowId ? [workflowId] : sharedWorkflowsIds,
// for backward compatibility `running` executions are always excluded
// unless the user explicitly filters by `running` status
excludedExecutionsIds: status !== 'running' ? runningExecutionsIds : undefined,
};
const executions =
await Container.get(ExecutionRepository).getExecutionsForPublicApi(filters);

View File

@@ -13,7 +13,7 @@ get:
required: false
schema:
type: string
enum: ['canceled', 'error', 'success', 'waiting']
enum: ['canceled', 'error', 'running', 'success', 'waiting']
- name: workflowId
in: query
description: Workflow to filter the executions by.

View File

@@ -24,6 +24,8 @@ properties:
stoppedAt:
type: string
format: date-time
nullable: true
description: The time at which the execution stopped. Will only be null for executions that still have the status 'running'.
workflowId:
type: number
example: '1000'

View File

@@ -402,12 +402,13 @@ describe('GET /executions', () => {
});
describe('with query status', () => {
type AllowedQueryStatus = 'success' | 'error' | 'canceled' | 'waiting';
type AllowedQueryStatus = 'canceled' | 'error' | 'running' | 'success' | 'waiting';
test.each`
queryStatus | entityStatus
${'canceled'} | ${'canceled'}
${'error'} | ${'error'}
${'error'} | ${'crashed'}
${'running'} | ${'running'}
${'success'} | ${'success'}
${'waiting'} | ${'waiting'}
`(
@@ -419,6 +420,10 @@ describe('GET /executions', () => {
const workflow = await createWorkflow({}, owner);
await createdExecutionWithStatus(workflow, queryStatus === 'success' ? 'error' : 'success');
if (queryStatus !== 'running') {
// ensure there is a running execution that gets excluded unless filtering by `running`
await createdExecutionWithStatus(workflow, 'running');
}
const expectedExecution = await createdExecutionWithStatus(workflow, entityStatus);