Mercurial > gemma
diff pkg/imports/bn.go @ 2195:3437ceee1529
Uploaded bottleneck import: Implemented in terms of normal bottleneck import.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 Feb 2019 11:54:12 +0100 |
parents | 7c83b5277c1c |
children | cce158db02b0 |
line wrap: on
line diff
--- a/pkg/imports/bn.go Tue Feb 12 11:09:55 2019 +0100 +++ b/pkg/imports/bn.go Tue Feb 12 11:54:12 2019 +0100 @@ -143,23 +143,41 @@ conn *sql.Conn, feedback Feedback, ) (interface{}, error) { - client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil) + + fetch := func(feedback Feedback) ([]*ifbn.BottleNeckType, error) { + client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil) + + req := &ifbn.Export_bn_by_isrs{} - req := &ifbn.Export_bn_by_isrs{} + resp, err := client.Export_bn_by_isrs(req) + if err != nil { + return nil, err + } + + if resp.Export_bn_by_isrsResult == nil { + return nil, errors.New("no Bottlenecks found") + } - resp, err := client.Export_bn_by_isrs(req) + return resp.Export_bn_by_isrsResult.BottleNeckType, nil + } + + return storeBottlenecks(ctx, fetch, importID, conn, feedback) +} + +func storeBottlenecks( + ctx context.Context, + fetch func(Feedback) ([]*ifbn.BottleNeckType, error), + importID int64, + conn *sql.Conn, + feedback Feedback, +) (interface{}, error) { + start := time.Now() + + bns, err := fetch(feedback) if err != nil { - feedback.Error("%v", err) return nil, err } - if resp.Export_bn_by_isrsResult == nil { - err := errors.New("no Bottlenecks found") - feedback.Error("%v", err) - return nil, err - } - - bns := resp.Export_bn_by_isrsResult.BottleNeckType feedback.Info("Found %d bottlenecks for import", len(bns)) tx, err := conn.BeginTx(ctx, nil) @@ -187,8 +205,6 @@ var nids []string - start := time.Now() - nextBN: for _, bn := range bns {