flow cleanup: separate TaskFunc from RunnerFunc
Extracted from #140 This will help be more flexible in what gets executed and how (e.g. for running tests for instance) Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
ef1bb4b873
commit
3628dbda84
@ -146,7 +146,7 @@ func (env *Env) LocalDirs() map[string]string {
|
||||
// 1. Scan the environment state
|
||||
// FIXME: use a common `flow` instance to avoid rescanning the tree.
|
||||
inst := env.state.CueInst()
|
||||
flow := cueflow.New(&cueflow.Config{}, inst, newDummyTaskFunc(inst))
|
||||
flow := cueflow.New(&cueflow.Config{}, inst, newTaskFunc(inst, noOpRunner))
|
||||
for _, t := range flow.Tasks() {
|
||||
v := compiler.Wrap(t.Value(), inst)
|
||||
localdirs(v.Get("#compute"))
|
||||
@ -225,7 +225,7 @@ func (env *Env) Compute(ctx context.Context, s Solver) error {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
// Cueflow cue instance
|
||||
flowInst := env.state.CueInst()
|
||||
inst := env.state.CueInst()
|
||||
|
||||
// Reset the output
|
||||
env.output = compiler.EmptyStruct()
|
||||
@ -260,7 +260,7 @@ func (env *Env) Compute(ctx context.Context, s Solver) error {
|
||||
},
|
||||
}
|
||||
// Orchestrate execution with cueflow
|
||||
flow := cueflow.New(flowCfg, flowInst, newPipelineTaskFunc(flowInst, s))
|
||||
flow := cueflow.New(flowCfg, inst, newTaskFunc(inst, newPipelineRunner(inst, s)))
|
||||
if err := flow.Run(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -273,27 +273,22 @@ func (env *Env) Compute(ctx context.Context, s Solver) error {
|
||||
}
|
||||
}
|
||||
|
||||
func newDummyTaskFunc(inst *cue.Instance) cueflow.TaskFunc {
|
||||
func newTaskFunc(inst *cue.Instance, runner cueflow.RunnerFunc) cueflow.TaskFunc {
|
||||
return func(flowVal cue.Value) (cueflow.Runner, error) {
|
||||
v := compiler.Wrap(flowVal, inst)
|
||||
if !isComponent(v) {
|
||||
// No compute script
|
||||
return nil, nil
|
||||
}
|
||||
return cueflow.RunnerFunc(func(t *cueflow.Task) error {
|
||||
return nil
|
||||
}), nil
|
||||
return runner, nil
|
||||
}
|
||||
}
|
||||
|
||||
func newPipelineTaskFunc(inst *cue.Instance, s Solver) cueflow.TaskFunc {
|
||||
return func(flowVal cue.Value) (cueflow.Runner, error) {
|
||||
v := compiler.Wrap(flowVal, inst)
|
||||
if !isComponent(v) {
|
||||
// No compute script
|
||||
return nil, nil
|
||||
}
|
||||
// Cueflow run func:
|
||||
func noOpRunner(t *cueflow.Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newPipelineRunner(inst *cue.Instance, s Solver) cueflow.RunnerFunc {
|
||||
return cueflow.RunnerFunc(func(t *cueflow.Task) error {
|
||||
ctx := t.Context()
|
||||
lg := log.
|
||||
@ -344,6 +339,5 @@ func newPipelineTaskFunc(inst *cue.Instance, s Solver) cueflow.TaskFunc {
|
||||
Dur("duration", time.Since(start)).
|
||||
Msg("completed")
|
||||
return nil
|
||||
}), nil
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user