MCPcopy Index your code
hub / github.com/garethgeorge/backrest / RunCommand

Method RunCommand

internal/api/backresthandler.go:633–668  ·  view source on GitHub ↗
(ctx context.Context, req *connect.Request[v1.RunCommandRequest])

Source from the content-addressed store, hash-verified

631}
632
633func (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
670func (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 {

Callers

nothing calls this directly

Calls 13

FindRepoFunction · 0.92
NewOneoffRunCommandTaskFunction · 0.92
SetReversedMethod · 0.80
SetLimitMethod · 0.80
SetRepoGUIDMethod · 0.80
SetInstanceIDMethod · 0.80
CreateUnscheduledTaskMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
RunTaskMethod · 0.65
GetGuidMethod · 0.45

Tested by

no test coverage detected