MCPcopy Index your code
hub / github.com/coder/coder / syncStart

Method syncStart

cli/sync_start.go:22–124  ·  view source on GitHub ↗
(socketPath *string)

Source from the content-addressed store, hash-verified

20)
21
22func (*RootCmd) syncStart(socketPath *string) *serpent.Command {
23 var timeout time.Duration
24
25 cmd := &serpent.Command{
26 Use: "start <unit>",
27 Short: "Wait until all unit dependencies are satisfied",
28 Long: "Wait until all dependencies are satisfied, consider the unit to have started, then allow it to proceed. This command polls until dependencies are ready, then marks the unit as started.",
29 Handler: func(i *serpent.Invocation) error {
30 ctx := i.Context()
31
32 if len(i.Args) != 1 {
33 return xerrors.New("exactly one unit name is required")
34 }
35 unitName := unit.ID(i.Args[0])
36
37 if timeout > 0 {
38 var cancel context.CancelFunc
39 ctx, cancel = context.WithTimeout(ctx, timeout)
40 defer cancel()
41 }
42
43 opts := []agentsocket.Option{}
44 if *socketPath != "" {
45 opts = append(opts, agentsocket.WithPath(*socketPath))
46 }
47
48 client, err := agentsocket.NewClient(ctx, opts...)
49 if err != nil {
50 return xerrors.Errorf("connect to agent socket: %w", err)
51 }
52 defer client.Close()
53
54 statusResp, err := client.SyncStatus(ctx, unitName)
55 if err != nil {
56 return xerrors.Errorf("get status failed: %w", err)
57 }
58 ready := statusResp.IsReady
59
60 var allDependencies []string
61 var unsatisfiedDependencies []string
62 for _, dep := range statusResp.Dependencies {
63 allDependencies = append(allDependencies, string(dep.DependsOn))
64 if !dep.IsSatisfied {
65 unsatisfiedDependencies = append(unsatisfiedDependencies, string(dep.DependsOn))
66 }
67 }
68 slices.Sort(allDependencies)
69 slices.Sort(unsatisfiedDependencies)
70
71 if !ready {
72 waitedForList := strings.Join(unsatisfiedDependencies, ", ")
73
74 cliui.Infof(i.Stdout, "Unit %q is waiting for dependencies to be satisfied: [%s]", unitName, waitedForList)
75
76 ticker := time.NewTicker(syncPollInterval)
77 defer ticker.Stop()
78
79 pollLoop:

Callers 1

syncCommandMethod · 0.95

Calls 15

CloseMethod · 0.95
SyncStatusMethod · 0.95
SyncReadyMethod · 0.95
SyncStartMethod · 0.95
IDTypeAlias · 0.92
WithPathFunction · 0.92
NewClientFunction · 0.92
InfofFunction · 0.92
InfoFunction · 0.92
ErrMethod · 0.80
ContextMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected