The workflow engine is the core component responsible for parsing, scheduling, and executing workflows. It is primarily implemented in js-core/src/domain/engine/engine.ts.
Key responsibilities include:
- Workflow Parsing: Converting definitions into internal models.
- Node Scheduling: Determining execution order based on edges.
- Node Execution: Invoking node executors.
- State & Variable Management: Tracking execution status and handling data transfer between nodes.
- Error Handling: Managing exceptions during the workflow lifecycle.
// Core method for workflow execution
public async run(params: RunParams): Promise<RunResult> {
const { schema, inputs, options } = params;
// Create workflow context
const context = this.createContext(schema, inputs, options);
try {
// Initialize workflow
await this.initialize(context);
// Execute workflow
await this.execute(context);
// Get workflow result
const result = await this.getResult(context);
return {
status: 'success',
outputs: result
};
} catch (error) {
// Error handling
return {
status: 'fail',
error: error.message
};
}
}