main can run many pipelines

main
Bel LaPointe 2024-04-15 16:23:41 -06:00
parent 83c0ee3f53
commit ff280997b1
1 changed files with 15 additions and 9 deletions

16
main.go
View File

@ -36,22 +36,28 @@ func run(ctx context.Context, cfg Config) error {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()
case err := <-processSlackToMessagePipeline(ctx, cfg): case err := <-processPipelines(ctx, cfg.slackToMessagePipeline):
return err return err
case err := <-listenAndServe(ctx, cfg): case err := <-listenAndServe(ctx, cfg):
return err return err
} }
} }
func processSlackToMessagePipeline(ctx context.Context, cfg Config) chan error { func processPipelines(ctx context.Context, first Pipeline, pipelines ...Pipeline) chan error {
ctx, can := context.WithCancel(ctx)
defer can()
pipelines = append(pipelines, first)
errs := make(chan error) errs := make(chan error)
go func() { for i := range pipelines {
go func(i int) {
defer close(errs) defer close(errs)
select { select {
case errs <- cfg.slackToMessagePipeline.Process(ctx): case errs <- pipelines[i].Process(ctx):
case <-ctx.Done(): case <-ctx.Done():
} }
}() }(i)
}
return errs return errs
} }