Added Scrape History Logging #9

Merged
SoXX merged 6 commits from dev/scrape-history into main 2024-10-16 10:15:59 +00:00
Showing only changes of commit a99c4457d2 - Show all commits

View File

@ -71,14 +71,14 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
span.RecordError(err) span.RecordError(err)
span.SetStatus(codes.Error, err.Error()) span.SetStatus(codes.Error, err.Error())
err = database.UpdateScrapeHistory(ctx, models.ScrapeHistory{ dberr := database.UpdateScrapeHistory(ctx, models.ScrapeHistory{
ScrapeTaskID: models.ScrapeTaskID(id), ScrapeTaskID: models.ScrapeTaskID(id),
UserSourceID: userSource.ID, UserSourceID: userSource.ID,
FinishedAt: time.Now(), FinishedAt: time.Now(),
Error: err.Error(), Error: err.Error(),
}) })
return nil, err return nil, errors.Join(err, dberr)
} }
span.AddEvent("Retrieved user source", trace.WithAttributes(attribute.String("user_source_id", creation.UserSourceId))) span.AddEvent("Retrieved user source", trace.WithAttributes(attribute.String("user_source_id", creation.UserSourceId)))
@ -91,14 +91,14 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
plugTaskState.TaskState = gRPC.PlugTaskState_STOPPED plugTaskState.TaskState = gRPC.PlugTaskState_STOPPED
err = database.UpdateScrapeHistory(ctx, models.ScrapeHistory{ dberr := database.UpdateScrapeHistory(ctx, models.ScrapeHistory{
ScrapeTaskID: models.ScrapeTaskID(id), ScrapeTaskID: models.ScrapeTaskID(id),
UserSourceID: userSource.ID, UserSourceID: userSource.ID,
FinishedAt: time.Now(), FinishedAt: time.Now(),
Error: err.Error(), Error: err.Error(),
}) })
return &plugTaskState, err return &plugTaskState, errors.Join(err, dberr)
} }
// gRPC closes the context after the call ended. So the whole scrapping stopped without waiting // gRPC closes the context after the call ended. So the whole scrapping stopped without waiting