forked from mtusi2026/mtusi2026lab6
fix(worker): lab6 propagate trace context to retry outbox
This commit is contained in:
@@ -73,7 +73,7 @@ func (p *Pipeline) Process(ctx context.Context, attachmentID string, pipelineVer
|
||||
}
|
||||
|
||||
fail := func(err error, permanent bool) error {
|
||||
outcome = p.handleFailure(a, err, permanent)
|
||||
outcome = p.handleFailure(context.WithoutCancel(ctx), a, err, permanent)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func endPipelineSpan(span trace.Span, err error) {
|
||||
span.End()
|
||||
}
|
||||
|
||||
func (p *Pipeline) handleFailure(a *domain.Attachment, err error, isPermanent bool) string {
|
||||
func (p *Pipeline) handleFailure(ctx context.Context, a *domain.Attachment, err error, isPermanent bool) string {
|
||||
// Если исчерпаны попытки или ошибка постоянная (например, битый файл)
|
||||
if isPermanent || a.Attempts >= p.maxRetries {
|
||||
reason := domain.JobErrorInternal
|
||||
@@ -205,7 +205,7 @@ func (p *Pipeline) handleFailure(a *domain.Attachment, err error, isPermanent bo
|
||||
jitter := time.Duration(rand.Intn(1000)) * time.Millisecond
|
||||
nextAt := time.Now().UTC().Add(backoff + jitter)
|
||||
|
||||
scheduleErr := p.jobs.ScheduleRetry(context.Background(), a.ID, nextAt, "")
|
||||
scheduleErr := p.jobs.ScheduleRetry(ctx, a.ID, nextAt, "")
|
||||
|
||||
// Кладем в Outbox отложенное сообщение
|
||||
payload, _ := json.Marshal(domain.JobMessage{
|
||||
@@ -213,7 +213,7 @@ func (p *Pipeline) handleFailure(a *domain.Attachment, err error, isPermanent bo
|
||||
PipelineVersion: a.PipelineVersion,
|
||||
Attempt: a.Attempts + 1,
|
||||
})
|
||||
enqueueErr := p.outbox.EnqueueDirect(context.Background(), &domain.OutboxEntry{
|
||||
enqueueErr := p.outbox.EnqueueDirect(ctx, &domain.OutboxEntry{
|
||||
AggregateType: domain.OutboxAggregateAttachment,
|
||||
AggregateID: a.ID,
|
||||
EventType: domain.OutboxEventProcess,
|
||||
|
||||
Reference in New Issue
Block a user