Skip to content

Commit

Permalink
refactor: customer workflow executor loading from yaml (#88)
Browse files Browse the repository at this point in the history
* refactor: error matcher

* refactor: step execution error

* refactor: step execution error

* refactor: step execution error

* refactor: customer workflow executor loading from yaml

Now executor loading will leaverage bindings instead of loading
separately.
  • Loading branch information
koladilip authored Aug 31, 2023
1 parent 4db8f5f commit a1cfb6c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/workflow/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class WorkflowEngineFactory {
try {
this.prepareWorkflow(workflow, options);
const optionsInteranl = options as WorkflowOptionsInternal;
const executor = await WorkflowUtils.getExecutor(workflow, optionsInteranl);
const bindings = await this.prepareBindings(workflow.bindings || [], optionsInteranl);
optionsInteranl.currentBindings = bindings;
const executor = await WorkflowUtils.getExecutor(workflow, optionsInteranl);
const stepExecutors = await this.createStepExecutors(workflow.steps, optionsInteranl);
return new WorkflowEngine(workflow.name, executor, bindings, stepExecutors);
} catch (error: any) {
Expand Down
6 changes: 2 additions & 4 deletions src/workflow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ export type Workflow = {
bindings?: Binding[];
steps: Step[];
templateType?: TemplateType;
executor?: {
name: string;
path: string;
};
// Executor name will be searched in the bindings
executor?: string;
};

export type WorkflowOutput = {
Expand Down
15 changes: 5 additions & 10 deletions src/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,12 @@ export class WorkflowUtils {
workflow: Workflow,
options: WorkflowOptionsInternal,
): Promise<WorkflowExecutor> {
if (workflow?.executor?.path) {
let executor = await this.getModuleExportsFromAllPaths(workflow.executor.path, options);

if (
!executor ||
!executor[workflow.executor.name] ||
!executor[workflow.executor.name].execute
) {
throw new WorkflowCreationError('Workflow executor not found', workflow.name);
if (workflow?.executor) {
let executor = options.currentBindings[workflow.executor];
if (!executor?.execute) {
throw new WorkflowCreationError('Workflow executor not found', workflow.executor);
}
return executor[workflow.executor.name];
return executor;
}
return options.executor || DefaultWorkflowExecutor.INSTANCE;
}
Expand Down
5 changes: 2 additions & 3 deletions test/scenarios/custom_executor/bad_executor.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
executor:
path: ./custom_executors
name: invalidExecutor
executor: invalidExecutor

steps:
- name: dummy
template: |
Expand Down
8 changes: 5 additions & 3 deletions test/scenarios/custom_executor/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
executor:
path: ./custom_executors
name: customWorkflowExecutor
bindings:
- path: ./custom_executors
name: customWorkflowExecutor

executor: customWorkflowExecutor
steps:
- name: dummy
template: |
Expand Down

0 comments on commit a1cfb6c

Please sign in to comment.