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 2707806a08 - Show all commits

View File

@ -70,6 +70,14 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
err = database.UpdateScrapeHistory(ctx, models.ScrapeHistory{
ScrapeTaskID: models.ScrapeTaskID(id),
UserSourceID: userSource.ID,
FinishedAt: time.Now(),
Error: err.Error(),
})
return nil, err
}
span.AddEvent("Retrieved user source", trace.WithAttributes(attribute.String("user_source_id", creation.UserSourceId)))
@ -83,6 +91,13 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
plugTaskState.TaskState = gRPC.PlugTaskState_STOPPED
err = database.UpdateScrapeHistory(ctx, models.ScrapeHistory{
ScrapeTaskID: models.ScrapeTaskID(id),
UserSourceID: userSource.ID,
FinishedAt: time.Now(),
Error: err.Error(),
})
return &plugTaskState, err
}
@ -100,6 +115,7 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
}).Debug("Starting task")
go func() {
var err error
taskSummery, err := s.taskExecutionFunction(taskCtx, userSource, creation.DeepScrape, creation.ApiKey)
if err != nil {
log.WithContext(taskCtx).WithError(err).WithField("task_id", id).Error("Task execution failed")