Skip to content

Commit

Permalink
Make it uniform.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Feb 19, 2025
1 parent 4f98c31 commit 6ceb851
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
8 changes: 7 additions & 1 deletion cmd/products/fooddata_central.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ func (f FoodDataCentral) Run(
return errE
}

config.Logger.Info().Int("total", len(foods)).Msg("retrieved FoodDataCentral data")

description := "FoodDataCentral processing"
progress := es.Progress(config.Logger, nil, nil, nil, description)
indexingSize.Add(int64(len(foods)))
Expand All @@ -612,10 +614,14 @@ func (f FoodDataCentral) Run(
}
}()

for _, food := range foods {
for i, food := range foods {
if ctx.Err() != nil {
return errors.WithStack(ctx.Err())
}
config.Logger.Debug().
Int("index", i).
Int("id", food.FDCID).
Msg("processing FoodDataCentral record")

ingredients, errE := getIngredients(f.IngredientsDir, food)
if errE != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/products/furs.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (d FURSDEJ) Run(
return errE
}

config.Logger.Info().Int("count", len(records)).Msg("retrieved FURS DEJ data")
config.Logger.Info().Int("total", len(records)).Msg("retrieved FURS DEJ data")

description := "FURS DEJ processing"
progress := es.Progress(config.Logger, nil, nil, nil, description)
Expand All @@ -169,7 +169,7 @@ func (d FURSDEJ) Run(
config.Logger.Debug().
Int("index", i).
Str("id", record.RegistrationNumber).
Msg("processing company record")
Msg("processing FURS DEJ record")

doc, errE := makeFursDoc(record)

Expand Down
2 changes: 1 addition & 1 deletion cmd/products/furs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestProcessFursDejFile(t *testing.T) {
if errE != nil {
require.NoError(t, errE, "% -+#.1v", errE)
}
require.Len(t, records, 8, "Expected 8 records, but got %d", len(records))
require.Len(t, records, 8, "expected 8 records, but got %d", len(records))

assert.NotEmpty(t, records)

Expand Down
8 changes: 7 additions & 1 deletion cmd/products/ljubljanske_mlekarne.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func (n LjubljanskeMlekarne) Run(
products = products.Union(ps)
}

config.Logger.Info().Int("total", products.Cardinality()).Msg("retrieved Ljubljanske mlekarne data")

description := "Ljubljanske mlekarne processing"
progress := es.Progress(config.Logger, nil, nil, nil, description)
indexingSize.Add(int64(products.Cardinality()))
Expand All @@ -183,10 +185,14 @@ func (n LjubljanskeMlekarne) Run(
}()

// TODO: Use Go iterators once supported. See: https://github.com/deckarep/golang-set/issues/141
for _, productURL := range products.ToSlice() {
for i, productURL := range products.ToSlice() {
if ctx.Err() != nil {
return errors.WithStack(ctx.Err())
}
config.Logger.Debug().
Int("index", i).
Str("url", productURL).
Msg("processing Ljubljanske mlekarne record")

product, errE := indexer.GetWebData[LjubljanskeMlekarneProduct](ctx, httpClient, productURL, indexer.ExtractData)
if errE != nil {
Expand Down
8 changes: 7 additions & 1 deletion cmd/products/natureta.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func (n Natureta) Run(
products.Append(ps.Products...)
}

config.Logger.Info().Int("total", products.Cardinality()).Msg("retrieved Natureta data")

description := "Natureta processing"
progress := es.Progress(config.Logger, nil, nil, nil, description)
indexingSize.Add(int64(products.Cardinality()))
Expand All @@ -233,10 +235,14 @@ func (n Natureta) Run(
}()

// TODO: Use Go iterators once supported. See: https://github.com/deckarep/golang-set/issues/141
for _, productURL := range products.ToSlice() {
for i, productURL := range products.ToSlice() {
if ctx.Err() != nil {
return errors.WithStack(ctx.Err())
}
config.Logger.Debug().
Int("index", i).
Str("url", productURL).
Msg("processing Natureta record")

product, errE := indexer.GetWebData[NaturetaProduct](ctx, httpClient, productURL, indexer.ExtractData)
if errE != nil {
Expand Down
9 changes: 8 additions & 1 deletion cmd/products/zito.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func (n Zito) Run(
products = products.Union(ps)
}

config.Logger.Info().Int("total", products.Cardinality()).Msg("retrieved Zito data")

description := "Zito processing"
progress := es.Progress(config.Logger, nil, nil, nil, description)
indexingSize.Add(int64(products.Cardinality()))
Expand All @@ -215,10 +217,14 @@ func (n Zito) Run(
}()

// TODO: Use Go iterators once supported. See: https://github.com/deckarep/golang-set/issues/141
for _, productURL := range products.ToSlice() {
for i, productURL := range products.ToSlice() {
if ctx.Err() != nil {
return errors.WithStack(ctx.Err())
}
config.Logger.Debug().
Int("index", i).
Str("url", productURL).
Msg("processing Zito record")

product, errE := indexer.GetWebData[ZitoProduct](ctx, httpClient, productURL, indexer.ExtractData)
if errE != nil {
Expand All @@ -228,6 +234,7 @@ func (n Zito) Run(
// Pages have HTML fragments they inject with JavaScript into the page.
productDetails, errE := indexer.ExtractData[ZitoProductDetails](strings.NewReader(product.Fragments))
if errE != nil {
errors.Details(errE)["url"] = productURL
return errE
}

Expand Down

0 comments on commit 6ceb851

Please sign in to comment.