mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user