handle skip reasons
This commit is contained in:
@ -83,14 +83,30 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error
|
|||||||
|
|
||||||
matcher := makeDefaultDimensionDispatcher()
|
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())
|
iter := getItemsIter(ctx, r.GoodsItem())
|
||||||
for iter.Next() {
|
for iter.Next() {
|
||||||
item := iter.Get()
|
item := iter.Get()
|
||||||
sublog := log.With().Int64("cart", item.Cart).Logger()
|
sublog := log.With().Int64("cart", item.Cart).Logger()
|
||||||
if item.Sizes == (entity.GoodsItemSize{}) {
|
if item.Sizes == (entity.GoodsItemSize{}) {
|
||||||
sublog.Warn().Str("sku", item.Articul).Int64("cart", item.Cart).Msg("skipping item because it does not have size")
|
sublog.Warn().Str("reason", reasonNoSize).Msg("skipping item")
|
||||||
skipped++
|
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
|
continue
|
||||||
}
|
}
|
||||||
@ -137,7 +153,7 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error
|
|||||||
enc.Indent("", " ")
|
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)
|
return enc.Encode(container)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user