refactor(core): Bring active executions into executions controller (no-changelog) (#8371)

This commit is contained in:
Iván Ovejero
2024-01-23 09:48:50 +01:00
committed by GitHub
parent 913c8c6b0c
commit 49b52c4f1d
22 changed files with 544 additions and 331 deletions

View File

@@ -1,18 +1,26 @@
import { ExecutionRequest } from './execution.request';
import type { GetManyActiveFilter } from './execution.types';
import { ExecutionRequest } from './execution.types';
import { ExecutionService } from './execution.service';
import { Authorized, Get, Post, RestController } from '@/decorators';
import { EnterpriseExecutionsService } from './execution.service.ee';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { WorkflowSharingService } from '@/workflows/workflowSharing.service';
import type { User } from '@/databases/entities/User';
import config from '@/config';
import { jsonParse } from 'n8n-workflow';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { ActiveExecutionService } from './active-execution.service';
@Authorized()
@RestController('/executions')
export class ExecutionsController {
private readonly isQueueMode = config.getEnv('executions.mode') === 'queue';
constructor(
private readonly executionService: ExecutionService,
private readonly enterpriseExecutionService: EnterpriseExecutionsService,
private readonly workflowSharingService: WorkflowSharingService,
private readonly activeExecutionService: ActiveExecutionService,
) {}
private async getAccessibleWorkflowIds(user: User) {
@@ -22,32 +30,64 @@ export class ExecutionsController {
}
@Get('/')
async getExecutionsList(req: ExecutionRequest.GetAll) {
async getMany(req: ExecutionRequest.GetMany) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.getExecutionsList(req, workflowIds);
if (workflowIds.length === 0) return { count: 0, estimated: false, results: [] };
return await this.executionService.findMany(req, workflowIds);
}
@Get('/active')
async getActive(req: ExecutionRequest.GetManyActive) {
const filter = req.query.filter?.length ? jsonParse<GetManyActiveFilter>(req.query.filter) : {};
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return this.isQueueMode
? await this.activeExecutionService.findManyInQueueMode(filter, workflowIds)
: await this.activeExecutionService.findManyInRegularMode(filter, workflowIds);
}
@Post('/active/:id/stop')
async stop(req: ExecutionRequest.Stop) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
if (workflowIds.length === 0) throw new NotFoundError('Execution not found');
const execution = await this.activeExecutionService.findOne(req.params.id, workflowIds);
if (!execution) throw new NotFoundError('Execution not found');
return await this.activeExecutionService.stop(execution);
}
@Get('/:id')
async getExecution(req: ExecutionRequest.Get) {
async getOne(req: ExecutionRequest.GetOne) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
if (workflowIds.length === 0) throw new NotFoundError('Execution not found');
return isSharingEnabled()
? await this.enterpriseExecutionService.getExecution(req, workflowIds)
: await this.executionService.getExecution(req, workflowIds);
? await this.enterpriseExecutionService.findOne(req, workflowIds)
: await this.executionService.findOne(req, workflowIds);
}
@Post('/:id/retry')
async retryExecution(req: ExecutionRequest.Retry) {
async retry(req: ExecutionRequest.Retry) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.retryExecution(req, workflowIds);
if (workflowIds.length === 0) throw new NotFoundError('Execution not found');
return await this.executionService.retry(req, workflowIds);
}
@Post('/delete')
async deleteExecutions(req: ExecutionRequest.Delete) {
async delete(req: ExecutionRequest.Delete) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.deleteExecutions(req, workflowIds);
if (workflowIds.length === 0) throw new NotFoundError('Execution not found');
return await this.executionService.delete(req, workflowIds);
}
}