From 44137a7251bb1bd142e11d7d18b9c2cae84303eb Mon Sep 17 00:00:00 2001 From: SoXX Date: Mon, 28 Oct 2024 21:08:54 +0100 Subject: [PATCH] feat: Add tracing events and logging for batch processing steps --- pkg/plug/algorithm.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/plug/algorithm.go b/pkg/plug/algorithm.go index 9a8c0ce..ed77874 100644 --- a/pkg/plug/algorithm.go +++ b/pkg/plug/algorithm.go @@ -72,7 +72,7 @@ outer: case <-ctx.Done(): break outer default: - + summery := BatchSummery{} span.AddEvent("Executing getFavorites request") favorites, err := plugInterface.GetFavoritePage(ctx, apiKey, userSource, nextPage) span.AddEvent("Finished executing getFavorites request") @@ -89,8 +89,9 @@ outer: break outer } - summery := BatchSummery{} + span.AddEvent("Executing BatchPostProcessingWithSummery") newPosts, anthroveFaves, summery, err = BatchPostProcessingWithSummery(ctx, userSource, favorites.Posts) + span.AddEvent("Finished executing BatchPostProcessingWithSummery") if err != nil { span.RecordError(err) span.SetStatus(codes.Error, err.Error()) @@ -98,6 +99,12 @@ outer: return taskSummery, err } + if len(anthroveFaves) > 0 { + span.AddEvent("No more favorites found to add") + log.WithContext(ctx).WithFields(basicLoggingInfo).Info("No more favorites found") + break outer + } + nextPage = favorites.NextPage taskSummery.AddedPosts += int(summery.AddedFavorites) } @@ -106,6 +113,7 @@ outer: } if len(newPosts) > 0 { + span.AddEvent("Executing CreatePostInBatch") err = database.CreatePostInBatch(ctx, newPosts, BatchSize) if err != nil { span.RecordError(err) @@ -118,6 +126,8 @@ outer: } if len(anthroveFaves) > 0 { + span.AddEvent("Executing CreateUserFavoriteInBatch") + slices.Reverse(anthroveFaves) err = database.CreateUserFavoriteInBatch(ctx, anthroveFaves, BatchSize) if err != nil {