feat: Add validation check for user account before starting task #5

Merged
SoXX merged 2 commits from dev/validation-check into main 2024-08-27 12:23:43 +00:00
Showing only changes of commit ea41bef942 - Show all commits

View File

@ -58,18 +58,10 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
}
span.AddEvent("Retrieved user source", trace.WithAttributes(attribute.String("user_source_id", creation.UserSourceId)))
// gRPC closes the context after the call ended. So the whole scrapping stopped without waiting
// by using this method we assign a new context to each new request we get.
// This can be used for example to close the context with the given id
ctx = trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{TraceID: span.SpanContext().TraceID()}))
taskCtx, cancel := context.WithCancel(ctx)
s.ctx[id] = cancel
span.AddEvent("Created new context for task", trace.WithAttributes(attribute.String("task_id", id)))
if !userSource.AccountValidate {
err = errors.New("user is not validated")
log.WithContext(taskCtx).WithError(err).WithField("task_id", id).Error("Task execution failed")
log.WithContext(ctx).WithError(err).WithField("task_id", id).Error("Task execution failed")
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
@ -78,6 +70,14 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
return &plugTaskState, err
}
// gRPC closes the context after the call ended. So the whole scrapping stopped without waiting
// by using this method we assign a new context to each new request we get.
// This can be used for example to close the context with the given id
ctx = trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{TraceID: span.SpanContext().TraceID()}))
taskCtx, cancel := context.WithCancel(ctx)
s.ctx[id] = cancel
span.AddEvent("Created new context for task", trace.WithAttributes(attribute.String("task_id", id)))
log.WithContext(taskCtx).WithFields(log.Fields{
"task_id": id,
"user_source_id": creation.UserSourceId,