Added Scrape History Logging #9
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user