(ctx context.Context, req *connect.Request[v1.RunCommandRequest])
| 631 | } |
| 632 | |
| 633 | func (s *BackrestHandler) RunCommand(ctx context.Context, req *connect.Request[v1.RunCommandRequest]) (*connect.Response[types.Int64Value], error) { |
| 634 | cfg, err := s.config.Get() |
| 635 | if err != nil { |
| 636 | return nil, fmt.Errorf("failed to get config: %w", err) |
| 637 | } |
| 638 | repo := config.FindRepo(cfg, req.Msg.RepoId) |
| 639 | if repo == nil { |
| 640 | return nil, connect.NewError(connect.CodeNotFound, fmt.Errorf("repo %q not found", req.Msg.RepoId)) |
| 641 | } |
| 642 | |
| 643 | // group commands within the last 24 hours (or 256 operations) into the same flow ID |
| 644 | var flowID int64 |
| 645 | if s.oplog.Query(oplog.Query{}. |
| 646 | SetInstanceID(cfg.Instance). |
| 647 | SetRepoGUID(repo.GetGuid()). |
| 648 | SetLimit(256). |
| 649 | SetReversed(true), func(op *v1.Operation) error { |
| 650 | if op.GetOperationRunCommand() != nil && time.Since(time.UnixMilli(op.UnixTimeStartMs)) < 30*time.Minute { |
| 651 | flowID = op.FlowId |
| 652 | } |
| 653 | return nil |
| 654 | }) != nil { |
| 655 | return nil, fmt.Errorf("failed to query operations") |
| 656 | } |
| 657 | |
| 658 | task := tasks.NewOneoffRunCommandTask(repo, tasks.PlanForSystemTasks, flowID, time.Now(), req.Msg.Command) |
| 659 | st, err := s.orchestrator.CreateUnscheduledTask(task, tasks.TaskPriorityInteractive, time.Now()) |
| 660 | if err != nil { |
| 661 | return nil, fmt.Errorf("failed to create task: %w", err) |
| 662 | } |
| 663 | if err := s.orchestrator.RunTask(context.Background(), st); err != nil { |
| 664 | return nil, fmt.Errorf("failed to run command: %w", err) |
| 665 | } |
| 666 | |
| 667 | return connect.NewResponse(&types.Int64Value{Value: st.Op.GetId()}), nil |
| 668 | } |
| 669 | |
| 670 | func (s *BackrestHandler) Cancel(ctx context.Context, req *connect.Request[types.Int64Value]) (*connect.Response[emptypb.Empty], error) { |
| 671 | if err := s.orchestrator.CancelOperation(req.Msg.Value, v1.OperationStatus_STATUS_USER_CANCELLED); err != nil { |
nothing calls this directly
no test coverage detected