CancelTask propagates manager-owned cancellation through the target task, affected runs, and all non-terminal descendants.
(ctx context.Context, id string, req CancelTask, actor ActorContext)
| 520 | // CancelTask propagates manager-owned cancellation through the target task, |
| 521 | // affected runs, and all non-terminal descendants. |
| 522 | func (m *Service) CancelTask(ctx context.Context, id string, req CancelTask, actor ActorContext) (*Task, error) { |
| 523 | if err := requireWriteAuthority(actor); err != nil { |
| 524 | return nil, err |
| 525 | } |
| 526 | |
| 527 | trimmedID := strings.TrimSpace(id) |
| 528 | if trimmedID == "" { |
| 529 | return nil, fmt.Errorf("%w: task id is required", ErrValidation) |
| 530 | } |
| 531 | normalizedReq, err := normalizeCancelTask(req) |
| 532 | if err != nil { |
| 533 | return nil, err |
| 534 | } |
| 535 | |
| 536 | tree, root, err := m.loadCancellationTree(ctx, trimmedID) |
| 537 | if err != nil { |
| 538 | return nil, err |
| 539 | } |
| 540 | if err := m.ensureTaskCancelable(ctx, root); err != nil { |
| 541 | return nil, err |
| 542 | } |
| 543 | |
| 544 | cancelledRoot := root |
| 545 | for idx, record := range tree { |
| 546 | record, err = m.cancelTaskTreeRecord(ctx, trimmedID, idx, record, normalizedReq, actor) |
| 547 | if err != nil { |
| 548 | return nil, err |
| 549 | } |
| 550 | if record.ID == trimmedID { |
| 551 | cancelledRoot = record |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return &cancelledRoot, nil |
| 556 | } |
| 557 | |
| 558 | func applyTaskPatch(current Task, patch Patch) (Task, []string) { |
| 559 | updated := current |
nothing calls this directly
no test coverage detected