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

Function fetchRuntimeResources

cli/show.go:65–109  ·  view source on GitHub ↗
(inv *serpent.Invocation, client *codersdk.Client, resources ...codersdk.WorkspaceResource)

Source from the content-addressed store, hash-verified

63}
64
65func fetchRuntimeResources(inv *serpent.Invocation, client *codersdk.Client, resources ...codersdk.WorkspaceResource) (map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse, map[uuid.UUID]codersdk.WorkspaceAgentListContainersResponse) {
66 ports := make(map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse)
67 devcontainers := make(map[uuid.UUID]codersdk.WorkspaceAgentListContainersResponse)
68 var wg sync.WaitGroup
69 var mu sync.Mutex
70 for _, res := range resources {
71 for _, agent := range res.Agents {
72 wg.Add(1)
73 go func() {
74 defer wg.Done()
75 lp, err := client.WorkspaceAgentListeningPorts(inv.Context(), agent.ID)
76 if err != nil {
77 cliui.Warnf(inv.Stderr, "Failed to get listening ports for agent %s: %v", agent.Name, err)
78 }
79 sort.Slice(lp.Ports, func(i, j int) bool {
80 return lp.Ports[i].Port < lp.Ports[j].Port
81 })
82 mu.Lock()
83 ports[agent.ID] = lp
84 mu.Unlock()
85 }()
86
87 if agent.ParentID.Valid {
88 continue
89 }
90 wg.Add(1)
91 go func() {
92 defer wg.Done()
93 dc, err := client.WorkspaceAgentListContainers(inv.Context(), agent.ID, map[string]string{
94 // Labels set by VSCode Remote Containers and @devcontainers/cli.
95 agentcontainers.DevcontainerConfigFileLabel: "",
96 agentcontainers.DevcontainerLocalFolderLabel: "",
97 })
98 if err != nil {
99 cliui.Warnf(inv.Stderr, "Failed to get devcontainers for agent %s: %v", agent.Name, err)
100 }
101 mu.Lock()
102 devcontainers[agent.ID] = dc
103 mu.Unlock()
104 }()
105 }
106 }
107 wg.Wait()
108 return ports, devcontainers
109}

Callers 1

showMethod · 0.85

Calls 9

WarnfFunction · 0.92
AddMethod · 0.65
ContextMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected