mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Bring active executions into executions controller (no-changelog) (#8371)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user