-
Notifications
You must be signed in to change notification settings - Fork 9
/
steps.go
62 lines (54 loc) · 2.04 KB
/
steps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package engine
import (
"fmt"
"go.arcalot.io/log/v2"
deployerRegistry "go.flow.arcalot.io/deployer/registry"
"go.flow.arcalot.io/engine/config"
"go.flow.arcalot.io/engine/internal/builtinfunctions"
"go.flow.arcalot.io/engine/internal/step"
"go.flow.arcalot.io/engine/internal/step/foreach"
"go.flow.arcalot.io/engine/internal/step/plugin"
stepRegistry "go.flow.arcalot.io/engine/internal/step/registry"
"go.flow.arcalot.io/engine/workflow"
)
// NewDefaultStepRegistry creates a registry with the default step types applied.
func NewDefaultStepRegistry(logger log.Logger, deployerRegistry deployerRegistry.Registry, config *config.Config) (step.Registry, error) {
pluginProvider, err := plugin.New(logger, deployerRegistry, config.LocalDeployers)
if err != nil {
return nil, fmt.Errorf("failed to create plugin step provider (%w)", err)
}
workflowFactory := &workflowFactory{
config: config,
}
loopProvider, err := foreach.New(logger, workflowFactory.createYAMLParser, workflowFactory.createWorkflow)
if err != nil {
return nil, fmt.Errorf("failed to create loop step provider (%w)", err)
}
stepR, err := stepRegistry.New(
pluginProvider,
loopProvider,
)
if err != nil {
return nil, fmt.Errorf("failed to create step registry (%w)", err)
}
workflowFactory.stepRegistry = stepR
return stepR, nil
}
type workflowFactory struct {
stepRegistry step.Registry
config *config.Config
}
func (f *workflowFactory) createYAMLParser() (workflow.YAMLConverter, error) {
stepR := f.stepRegistry
if stepR == nil {
return nil, fmt.Errorf("YAML converter not available yet, please call the factory function after the engine has initialized")
}
return workflow.NewYAMLConverter(stepR), nil
}
func (f *workflowFactory) createWorkflow(logger log.Logger) (workflow.Executor, error) {
stepR := f.stepRegistry
if stepR == nil {
return nil, fmt.Errorf("YAML converter not available yet, please call the factory function after the engine has initialized")
}
return workflow.NewExecutor(logger, f.config, stepR, builtinfunctions.GetFunctions())
}