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 ExecutorService with virtual threads (Project Loom) to handle high-concurrency node execution efficiently.
  • Error Handling: Managing global timeout policies, node retries, and failure propagation.

Execution Flow

  1. Resolution of Trigger Nodes (start points).
  2. Breadth-First Search (BFS) or topological traversal of the graph.
  3. Delegation of specific tasks to the appropriate NodeExecutor.
  4. Parameter interpolation and variable resolution.
See Also:
  • 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 repository
      workflowService - the workflow service
      credentialService - the credential service
      nodeExecutorRegistry - the node executor registry
      objectMapper - the object mapper
      executionLogger - the execution logger
      settingsService - the settings service
      devModeService - the dev mode service
      logHandlers - 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

      public List<ai.nervemind.common.dto.ExecutionDTO> findAll()
      Specified by:
      findAll in interface ai.nervemind.common.service.ExecutionServiceInterface
    • findById

      public Optional<ai.nervemind.common.dto.ExecutionDTO> findById(Long id)
      Specified by:
      findById in interface ai.nervemind.common.service.ExecutionServiceInterface
    • findByWorkflowId

      public List<ai.nervemind.common.dto.ExecutionDTO> findByWorkflowId(Long workflowId)
      Specified by:
      findByWorkflowId in interface ai.nervemind.common.service.ExecutionServiceInterface
    • findRunningExecutions

      public List<ai.nervemind.common.dto.ExecutionDTO> findRunningExecutions()
      Specified by:
      findRunningExecutions in interface ai.nervemind.common.service.ExecutionServiceInterface
    • deleteAll

      public void deleteAll()
      Specified by:
      deleteAll in interface ai.nervemind.common.service.ExecutionServiceInterface
    • findByTimeRange

      public List<ai.nervemind.common.dto.ExecutionDTO> findByTimeRange(Instant start, Instant end)
      Specified by:
      findByTimeRange in interface ai.nervemind.common.service.ExecutionServiceInterface
    • executeAsync

      public CompletableFuture<ai.nervemind.common.dto.ExecutionDTO> executeAsync(Long workflowId, Map<String,Object> input)
      Execute a workflow asynchronously.
      Specified by:
      executeAsync in interface ai.nervemind.common.service.ExecutionServiceInterface
    • execute

      public ai.nervemind.common.dto.ExecutionDTO execute(Long workflowId, Map<String,Object> input)
      Execute a workflow synchronously.
      Specified by:
      execute in interface ai.nervemind.common.service.ExecutionServiceInterface
    • cancelExecution

      public boolean cancelExecution(Long executionId)
      Cancel a running execution. Sets the cancellation flag which will be checked during node execution.
      Specified by:
      cancelExecution in interface ai.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

      public int cancelAllForWorkflow(Long workflowId)
      Cancel all running executions for a workflow.
      Specified by:
      cancelAllForWorkflow in interface ai.nervemind.common.service.ExecutionServiceInterface
      Parameters:
      workflowId - the workflow ID
      Returns:
      the number of executions cancelled