ToolJet/server/src/modules/workflows/controllers/workflow-executions.controller.ts

74 lines
2.7 KiB
TypeScript
Raw Normal View History

feat: Setup async workflow query execution with SSE Overview This PR implements real-time workflow execution monitoring using Server-Sent Events (SSE) as part of our LTS feature support. The implementation allows for tracking long-running workflows without requiring deployment changes. Technical Changes 1. Server Components Added WorkflowStreamService to manage persistent SSE streams with automatic cleanup Implemented @sse endpoint in WorkflowExecutionsController for streaming status updates Created WorkflowTriggersListener to emit workflow execution events with EventEmitter2 Added workflow execution status constants to identify different states in the execution lifecycle 2. Client-side Components Implemented AsyncQueryHandler to manage SSE connections and parse event streams Enhanced queryPanelSlice with methods to create async handlers and trigger workflows Added support for non-blocking workflow execution with real-time status updates 3. Workflow Integration Modified workflow triggering to use the SSE-based monitoring approach Maintained same-server architecture to avoid deployment changes Added automatic reconnection handling and error recovery for client connections Architecture Decisions Selected Same Server Approach: Chose to implement workflows within the same HTTP server to maintain the existing deployment setup for LTS users Real-time Updates with SSE: Leveraged Server-Sent Events for their simplicity, efficiency, and compatibility with existing infrastructure Future Extension Path: Implementation can be extended to Worker Threads or Microservice architecture later if needed
2025-07-01 13:47:07 +00:00
import { Body, Controller, Get, Param, Post, Res, Sse } from '@nestjs/common';
2025-02-25 06:52:50 +00:00
import { Response } from 'express';
import { IWorkflowExecutionController } from '../interfaces/IWorkflowExecutionController';
import { CreateWorkflowExecutionDto } from '@dto/create-workflow-execution.dto';
import { WorkflowExecution } from 'src/entities/workflow_execution.entity';
import { PreviewWorkflowNodeDto } from '@dto/preview-workflow-node.dto';
import { User } from '@modules/app/decorators/user.decorator';
import { InitModule } from '@modules/app/decorators/init-module';
import { MODULES } from '@modules/app/constants/modules';
import { InitFeature } from '@modules/app/decorators/init-feature.decorator';
import { FEATURE_KEY } from '@modules/workflows/constants';
feat: Setup async workflow query execution with SSE Overview This PR implements real-time workflow execution monitoring using Server-Sent Events (SSE) as part of our LTS feature support. The implementation allows for tracking long-running workflows without requiring deployment changes. Technical Changes 1. Server Components Added WorkflowStreamService to manage persistent SSE streams with automatic cleanup Implemented @sse endpoint in WorkflowExecutionsController for streaming status updates Created WorkflowTriggersListener to emit workflow execution events with EventEmitter2 Added workflow execution status constants to identify different states in the execution lifecycle 2. Client-side Components Implemented AsyncQueryHandler to manage SSE connections and parse event streams Enhanced queryPanelSlice with methods to create async handlers and trigger workflows Added support for non-blocking workflow execution with real-time status updates 3. Workflow Integration Modified workflow triggering to use the SSE-based monitoring approach Maintained same-server architecture to avoid deployment changes Added automatic reconnection handling and error recovery for client connections Architecture Decisions Selected Same Server Approach: Chose to implement workflows within the same HTTP server to maintain the existing deployment setup for LTS users Real-time Updates with SSE: Leveraged Server-Sent Events for their simplicity, efficiency, and compatibility with existing infrastructure Future Extension Path: Implementation can be extended to Worker Threads or Microservice architecture later if needed
2025-07-01 13:47:07 +00:00
import { Observable } from 'rxjs';
2025-02-25 06:52:50 +00:00
@InitModule(MODULES.WORKFLOWS)
@Controller('workflow_executions')
export class WorkflowExecutionsController implements IWorkflowExecutionController {
constructor() {}
@InitFeature(FEATURE_KEY.EXECUTE_WORKFLOW)
@Post()
async create(
@User() user,
@Body() createWorkflowExecutionDto: CreateWorkflowExecutionDto,
@Res({ passthrough: true }) response: Response
): Promise<{ workflowExecution: WorkflowExecution; result: any }> {
throw new Error('Method not implemented.');
}
@InitFeature(FEATURE_KEY.WORKFLOW_EXECUTION_STATUS)
@Get(':id/status')
async status(@Param('id') id: any, @User() user): Promise<any> {
throw new Error('Method not implemented.');
}
@InitFeature(FEATURE_KEY.WORKFLOW_EXECUTION_DETAILS)
@Get(':id')
async show(@Param('id') id: any, @User() user): Promise<WorkflowExecution> {
throw new Error('Method not implemented.');
}
@InitFeature(FEATURE_KEY.LIST_WORKFLOW_EXECUTIONS)
@Get('all/:appVersionId')
async index(@Param('appVersionId') appVersionId: any, @User() user): Promise<WorkflowExecution[]> {
throw new Error('Method not implemented.');
}
@InitFeature(FEATURE_KEY.PREVIEW_QUERY_NODE)
@Post('previewQueryNode')
async previewQueryNode(
@User() user,
@Body() previewNodeDto: PreviewWorkflowNodeDto,
@Res({ passthrough: true }) response: Response
): Promise<{ result: any }> {
throw new Error('Method not implemented.');
}
feat: Setup async workflow query execution with SSE Overview This PR implements real-time workflow execution monitoring using Server-Sent Events (SSE) as part of our LTS feature support. The implementation allows for tracking long-running workflows without requiring deployment changes. Technical Changes 1. Server Components Added WorkflowStreamService to manage persistent SSE streams with automatic cleanup Implemented @sse endpoint in WorkflowExecutionsController for streaming status updates Created WorkflowTriggersListener to emit workflow execution events with EventEmitter2 Added workflow execution status constants to identify different states in the execution lifecycle 2. Client-side Components Implemented AsyncQueryHandler to manage SSE connections and parse event streams Enhanced queryPanelSlice with methods to create async handlers and trigger workflows Added support for non-blocking workflow execution with real-time status updates 3. Workflow Integration Modified workflow triggering to use the SSE-based monitoring approach Maintained same-server architecture to avoid deployment changes Added automatic reconnection handling and error recovery for client connections Architecture Decisions Selected Same Server Approach: Chose to implement workflows within the same HTTP server to maintain the existing deployment setup for LTS users Real-time Updates with SSE: Leveraged Server-Sent Events for their simplicity, efficiency, and compatibility with existing infrastructure Future Extension Path: Implementation can be extended to Worker Threads or Microservice architecture later if needed
2025-07-01 13:47:07 +00:00
@InitFeature(FEATURE_KEY.EXECUTE_WORKFLOW)
@Post(':id/trigger')
async trigger(
@Param('id') id: string,
@Body() createWorkflowExecutionDto: CreateWorkflowExecutionDto,
@User() user,
@Res({ passthrough: true }) response: Response
): Promise<{ result: any }> {
throw new Error('Method not implemented.');
}
@InitFeature(FEATURE_KEY.WORKFLOW_EXECUTION_STATUS)
@Sse(':id/stream')
streamWorkflowExecution(@Param('id') id: string): Observable<MessageEvent> {
throw new Error('Method not implemented.');
}
2025-02-25 06:52:50 +00:00
}