main can run many pipelines
parent
83c0ee3f53
commit
ff280997b1
16
main.go
16
main.go
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue