fix: move before new context gets created
This commit is contained in:
parent
caef31f48f
commit
ea41bef942
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user