( ctx context.Context, id string, req ExecutionRequest, action ExecutionAction, actor ActorContext, )
| 667 | } |
| 668 | |
| 669 | func (m *Service) executeTaskBoundary( |
| 670 | ctx context.Context, |
| 671 | id string, |
| 672 | req ExecutionRequest, |
| 673 | action ExecutionAction, |
| 674 | actor ActorContext, |
| 675 | ) (*Execution, error) { |
| 676 | if err := requireWriteAuthority(actor); err != nil { |
| 677 | return nil, err |
| 678 | } |
| 679 | trimmedID := strings.TrimSpace(id) |
| 680 | if trimmedID == "" { |
| 681 | return nil, fmt.Errorf("%w: task id is required", ErrValidation) |
| 682 | } |
| 683 | normalizedReq, err := normalizeTaskExecutionRequest(req) |
| 684 | if err != nil { |
| 685 | return nil, err |
| 686 | } |
| 687 | if err := m.validateNetworkChannel("task_execution.network_channel", normalizedReq.NetworkChannel); err != nil { |
| 688 | return nil, err |
| 689 | } |
| 690 | idempotencyKey := taskExecutionIdempotencyKey(trimmedID, action, normalizedReq.IdempotencyKey) |
| 691 | if existing, ok, err := m.taskExecutionFromIdempotency(ctx, trimmedID, idempotencyKey, action, actor); err != nil { |
| 692 | return nil, err |
| 693 | } else if ok { |
| 694 | return existing, nil |
| 695 | } |
| 696 | |
| 697 | approvalTask, err := m.prepareTaskExecutionBoundary(ctx, trimmedID, action, actor) |
| 698 | if err != nil { |
| 699 | return nil, err |
| 700 | } |
| 701 | |
| 702 | if execution, ok, err := m.approvalAutoEnqueueExecution( |
| 703 | ctx, |
| 704 | approvalTask, |
| 705 | normalizedReq, |
| 706 | idempotencyKey, |
| 707 | actor, |
| 708 | ); err != nil { |
| 709 | return nil, err |
| 710 | } else if ok { |
| 711 | return execution, nil |
| 712 | } |
| 713 | |
| 714 | run, err := m.EnqueueRun(ctx, EnqueueRun{ |
| 715 | TaskID: trimmedID, |
| 716 | IdempotencyKey: idempotencyKey, |
| 717 | NetworkChannel: normalizedReq.NetworkChannel, |
| 718 | Metadata: normalizedReq.Metadata, |
| 719 | }, actor) |
| 720 | if err != nil { |
| 721 | return nil, err |
| 722 | } |
| 723 | taskRecord, err := m.store.GetTask(ctx, run.TaskID) |
| 724 | if err != nil { |
| 725 | return nil, err |
| 726 | } |
no test coverage detected