From 85a42dc4050c3effface173f30171e5e1230903b Mon Sep 17 00:00:00 2001 From: dilap54 Date: Thu, 21 Dec 2023 22:13:18 +0300 Subject: [PATCH] threads --- cmd/cli/plati.go | 4 +++- plati/goodscategory.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/cli/plati.go b/cmd/cli/plati.go index 253f9de..07c5e5c 100644 --- a/cmd/cli/plati.go +++ b/cmd/cli/plati.go @@ -34,7 +34,7 @@ var platiCommand = &cli.Command{ // printNames(categories) wg, _ := errgroup.WithContext(ctx) - wg.SetLimit(30) + wg.SetLimit(10) for i, c := range categories { l := i @@ -48,6 +48,8 @@ var platiCommand = &cli.Command{ if len(goods) == 0 { return nil } + log.Printf("inserting %d goods to DB", len(goods)) + gormGoods := convertGoodsToGorm(cat, goods) if err := db.Create(gormGoods).Error; err != nil { return fmt.Errorf("db Create: %w", err) diff --git a/plati/goodscategory.go b/plati/goodscategory.go index dfd5b68..ee5768f 100644 --- a/plati/goodscategory.go +++ b/plati/goodscategory.go @@ -34,6 +34,10 @@ func (c *Client) GetBlockGoodsCategory(ctx context.Context, idC int, idR int, so defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("status code: %d", resp.StatusCode) + } + goods, err := parseGoodsCategory(resp.Body) if err != nil { return nil, fmt.Errorf("parse goods category: %w", err)