Class ExecutionService
java.lang.Object
ai.nervemind.app.service.ExecutionService
- All Implemented Interfaces:
ai.nervemind.common.service.ExecutionServiceInterface
@Service
@Transactional
public class ExecutionService
extends Object
implements ai.nervemind.common.service.ExecutionServiceInterface
Core workflow execution engine service.
Responsible for the lifecycle and orchestration of workflow executions. This service acts as the central nervous system of NerveMind, managing:
- Orchestration: Traversing the workflow graph (directed acyclic graph) and determining the execution order of nodes.
- State Management: Persisting execution status, logs, and
intermediate data in the
ExecutionRepository. - Concurrency: leveraging
ExecutorServicewith virtual threads (Project Loom) to handle high-concurrency node execution efficiently. - Error Handling: Managing global timeout policies, node retries, and failure propagation.
Execution Flow
- Resolution of Trigger Nodes (start points).
- Breadth-First Search (BFS) or topological traversal of the graph.
- Delegation of specific tasks to the appropriate
NodeExecutor. - Parameter interpolation and variable resolution.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExecution context holds state during workflow execution. -
Constructor Summary
ConstructorsConstructorDescriptionExecutionService(ExecutionRepository executionRepository, WorkflowService workflowService, CredentialService credentialService, NodeExecutorRegistry nodeExecutorRegistry, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExecutionLogger executionLogger, ai.nervemind.common.service.SettingsServiceInterface settingsService, ai.nervemind.common.service.DevModeServiceInterface devModeService, List<ai.nervemind.common.service.ExecutionLogHandler> logHandlers) Creates a new execution service. -
Method Summary
Modifier and TypeMethodDescriptionintcancelAllForWorkflow(Long workflowId) Cancel all running executions for a workflow.booleancancelExecution(Long executionId) Cancel a running execution.voidai.nervemind.common.dto.ExecutionDTOExecute a workflow synchronously.CompletableFuture<ai.nervemind.common.dto.ExecutionDTO> executeAsync(Long workflowId, Map<String, Object> input) Execute a workflow asynchronously.List<ai.nervemind.common.dto.ExecutionDTO> findAll()Optional<ai.nervemind.common.dto.ExecutionDTO> List<ai.nervemind.common.dto.ExecutionDTO> findByTimeRange(Instant start, Instant end) List<ai.nervemind.common.dto.ExecutionDTO> findByWorkflowId(Long workflowId) List<ai.nervemind.common.dto.ExecutionDTO> intGets the default execution timeout from settings.intGets the maximum number of parallel nodes from settings.intGets the default retry attempts from settings.longGets the default retry delay from settings.
-
Constructor Details
-
ExecutionService
public ExecutionService(ExecutionRepository executionRepository, WorkflowService workflowService, CredentialService credentialService, NodeExecutorRegistry nodeExecutorRegistry, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExecutionLogger executionLogger, ai.nervemind.common.service.SettingsServiceInterface settingsService, ai.nervemind.common.service.DevModeServiceInterface devModeService, List<ai.nervemind.common.service.ExecutionLogHandler> logHandlers) Creates a new execution service.- Parameters:
executionRepository- the execution repositoryworkflowService- the workflow servicecredentialService- the credential servicenodeExecutorRegistry- the node executor registryobjectMapper- the object mapperexecutionLogger- the execution loggersettingsService- the settings servicedevModeService- the dev mode servicelogHandlers- the log handlers
-
-
Method Details
-
getDefaultTimeout
public int getDefaultTimeout()Gets the default execution timeout from settings.- Returns:
- timeout in milliseconds
-
getMaxParallelNodes
public int getMaxParallelNodes()Gets the maximum number of parallel nodes from settings.- Returns:
- the maximum number of parallel nodes
-
getRetryAttempts
public int getRetryAttempts()Gets the default retry attempts from settings.- Returns:
- the default retry attempts
-
getRetryDelay
public long getRetryDelay()Gets the default retry delay from settings.- Returns:
- delay in milliseconds
-
findAll
- Specified by:
findAllin interfaceai.nervemind.common.service.ExecutionServiceInterface
-
findById
-
findByWorkflowId
-
findRunningExecutions
- Specified by:
findRunningExecutionsin interfaceai.nervemind.common.service.ExecutionServiceInterface
-
deleteAll
public void deleteAll()- Specified by:
deleteAllin interfaceai.nervemind.common.service.ExecutionServiceInterface
-
findByTimeRange
-
executeAsync
public CompletableFuture<ai.nervemind.common.dto.ExecutionDTO> executeAsync(Long workflowId, Map<String, Object> input) Execute a workflow asynchronously.- Specified by:
executeAsyncin interfaceai.nervemind.common.service.ExecutionServiceInterface
-
execute
-
cancelExecution
Cancel a running execution. Sets the cancellation flag which will be checked during node execution.- Specified by:
cancelExecutionin interfaceai.nervemind.common.service.ExecutionServiceInterface- Parameters:
executionId- the ID of the execution to cancel- Returns:
- true if the execution was cancelled, false if not found or not running
-
cancelAllForWorkflow
Cancel all running executions for a workflow.- Specified by:
cancelAllForWorkflowin interfaceai.nervemind.common.service.ExecutionServiceInterface- Parameters:
workflowId- the workflow ID- Returns:
- the number of executions cancelled
-