bust/pkg/pipelines/pipeline.go
kjuulh 6c885ec33c
All checks were successful
continuous-integration/drone/push Build is passing
with rust template
2022-11-06 00:39:03 +01:00

45 lines
839 B
Go

package pipelines
import (
"context"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/byg"
"golang.org/x/sync/errgroup"
)
type Pipeline struct {
builder *builder.Builder
pipelines []*byg.Builder
}
func New(builder *builder.Builder) *Pipeline {
return &Pipeline{builder: builder}
}
func (p *Pipeline) WithCustom(custom func(p *Pipeline) *byg.Builder) {
p.add(custom(p))
}
func (p *Pipeline) Execute(ctx context.Context) error {
errgroup, ctx := errgroup.WithContext(ctx)
for _, pipeline := range p.pipelines {
pipeline := pipeline // Allocate for closure
errgroup.Go(func() error {
return pipeline.Execute(ctx)
})
}
if err := errgroup.Wait(); err != nil {
return err
}
return nil
}
func (p *Pipeline) add(pipeline *byg.Builder) {
p.pipelines = append(p.pipelines, pipeline)
}