Skip to content

Commit

Permalink
fix: moving task lock befor status check (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Farhadnia authored Jul 17, 2024
1 parent 5abba61 commit 38fa2a6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions destination/taskservice/handle_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,24 @@ func (s Service) HandleTask(ctx context.Context, newEvent event.ProcessedEvent)
newEvent.TracerCarrier = otela.GetCarrierFromContext(ctx)
span.AddEvent("start-handle-task")

var taskStatus taskentity.IntegrationDeliveryStatus
taskID := newEvent.ID()

unlock, err := s.LockTaskByID(ctx, taskID)
if err != nil {
span.AddEvent("error-on-lock-task", trace.WithAttributes(
attribute.String("error", err.Error())))

return err
}
defer func() {
unlockErr := unlock()
if unlockErr != nil {
logger.L().Error(fmt.Sprintf("unlock task failed %s", unlockErr))
}
}()

var taskStatus taskentity.IntegrationDeliveryStatus

// Get task status using idempotency in the task service.
if taskStatus, err = s.GetTaskStatusByID(ctx, taskID); err != nil {
span.AddEvent("error-on-get-task-status", trace.WithAttributes(
Expand All @@ -44,20 +59,6 @@ func (s Service) HandleTask(ctx context.Context, newEvent event.ProcessedEvent)
return nil
}

unlock, err := s.LockTaskByID(ctx, taskID)
if err != nil {
span.AddEvent("error-on-lock-task", trace.WithAttributes(
attribute.String("error", err.Error())))

return err
}
defer func() {
err = unlock()
if err != nil {
logger.L().Error(fmt.Sprintf("unlock task failed %s", err))
}
}()

span.AddEvent("task-status-retrieved", trace.WithAttributes(
attribute.String("status", taskStatus.String()),
))
Expand Down

0 comments on commit 38fa2a6

Please sign in to comment.