feat: Add tracing events and logging for batch processing steps
All checks were successful
Gitea Build Check / Build (push) Successful in 58s
Gitea Build Check / Build (pull_request) Successful in 57s

This commit is contained in:
SoXX 2024-10-28 21:08:54 +01:00
parent b2db0664d6
commit 44137a7251

View File

@ -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 {