Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: customer workflow executor loading from yaml #88

Merged
merged 12 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading