CancelPlanCheckRun cancels the plan check run for a plan.
(ctx context.Context, request *connect.Request[v1pb.CancelPlanCheckRunRequest])
| 528 | |
| 529 | // CancelPlanCheckRun cancels the plan check run for a plan. |
| 530 | func (s *PlanService) CancelPlanCheckRun(ctx context.Context, request *connect.Request[v1pb.CancelPlanCheckRunRequest]) (*connect.Response[v1pb.CancelPlanCheckRunResponse], error) { |
| 531 | req := request.Msg |
| 532 | projectID, planUID, err := common.GetProjectIDPlanIDFromPlanCheckRun(req.Name) |
| 533 | if err != nil { |
| 534 | return nil, connect.NewError(connect.CodeInvalidArgument, err) |
| 535 | } |
| 536 | |
| 537 | project, err := s.store.GetProject(ctx, &store.FindProjectMessage{ |
| 538 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 539 | ResourceID: &projectID, |
| 540 | }) |
| 541 | if err != nil { |
| 542 | return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to find project")) |
| 543 | } |
| 544 | if project == nil { |
| 545 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("project %v not found", projectID)) |
| 546 | } |
| 547 | |
| 548 | planCheckRun, err := s.store.GetPlanCheckRun(ctx, projectID, planUID) |
| 549 | if err != nil { |
| 550 | return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get plan check run")) |
| 551 | } |
| 552 | if planCheckRun == nil { |
| 553 | return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("plan check run not found for plan %d", planUID)) |
| 554 | } |
| 555 | |
| 556 | if planCheckRun.Status != store.PlanCheckRunStatusRunning && planCheckRun.Status != store.PlanCheckRunStatusAvailable { |
| 557 | return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("plan check run is not running or available")) |
| 558 | } |
| 559 | |
| 560 | // Cancel in-flight plan check run if running. |
| 561 | if cancelFunc, ok := s.bus.RunningPlanCheckRunsCancelFunc.Load(bus.PlanCheckRunRef{ProjectID: projectID, UID: planCheckRun.UID}); ok { |
| 562 | cancelFunc.(context.CancelFunc)() |
| 563 | } |
| 564 | |
| 565 | // Broadcast cancel signal to all replicas for HA. |
| 566 | if err := s.store.SendSignal(ctx, storepb.Signal_CANCEL_PLAN_CHECK_RUN, projectID, planCheckRun.UID); err != nil { |
| 567 | slog.Warn("failed to send cancel signal", log.BBError(err)) |
| 568 | } |
| 569 | |
| 570 | // Update the status to canceled. |
| 571 | if err := s.store.BatchCancelPlanCheckRuns(ctx, projectID, []int64{planCheckRun.UID}); err != nil { |
| 572 | return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to cancel plan check run")) |
| 573 | } |
| 574 | |
| 575 | return connect.NewResponse(&v1pb.CancelPlanCheckRunResponse{}), nil |
| 576 | } |
| 577 | |
| 578 | func validateSpecs(ctx context.Context, s *store.Store, projectID string, specs []*v1pb.Plan_Spec) (*v1pb.DatabaseGroup, error) { |
| 579 | if len(specs) == 0 { |
nothing calls this directly
no test coverage detected