From 149cde5b223f3d535fdd82c16a01b0088f1a3b61 Mon Sep 17 00:00:00 2001 From: Aleksandr Trushkin Date: Tue, 13 Feb 2024 21:24:05 +0300 Subject: [PATCH] handle skip reasons --- cmd/cli/commands/exports.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/cli/commands/exports.go b/cmd/cli/commands/exports.go index 6584d4f..b6b281b 100644 --- a/cmd/cli/commands/exports.go +++ b/cmd/cli/commands/exports.go @@ -83,14 +83,30 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error matcher := makeDefaultDimensionDispatcher() - var skipped int + const ( + reasonNoSize = "no_size" + reasonTooLarge = "too_large" + ) + + skippedByReasons := map[string]int{ + reasonNoSize: 0, + reasonTooLarge: 0, + } iter := getItemsIter(ctx, r.GoodsItem()) for iter.Next() { item := iter.Get() sublog := log.With().Int64("cart", item.Cart).Logger() if item.Sizes == (entity.GoodsItemSize{}) { - sublog.Warn().Str("sku", item.Articul).Int64("cart", item.Cart).Msg("skipping item because it does not have size") - skipped++ + sublog.Warn().Str("reason", reasonNoSize).Msg("skipping item") + skippedByReasons[reasonNoSize]++ + + continue + } + + const maximumAllowedSizes = 160 + if sum := item.Sizes.GetSum(entity.DimensionKindCentimeter); sum > maximumAllowedSizes { + sublog.Warn().Str("reason", reasonTooLarge).Msg("skipping item") + skippedByReasons[reasonTooLarge]++ continue } @@ -137,7 +153,7 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error enc.Indent("", " ") } - log.Info().Int("processed", len(shop.Offers)).Int("skipped", skipped).Msg("completed") + log.Info().Int("processed", len(shop.Offers)).Any("skipped", skippedByReasons).Msg("completed") return enc.Encode(container) }