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

Method run

coderd/workspaceconnwatcher/watcher.go:170–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

168}
169
170func (u *updater) run() {
171 u.enc = wsjson.NewEncoder[workspacesdk.ConnectionWatchEvent](u.conn, websocket.MessageText)
172 defer func() {
173 // this is a no-op if we have already closed for some other reason.
174 _ = u.enc.Close(websocket.StatusNormalClosure)
175 }()
176
177 for {
178 select {
179 case <-u.watcherCtx.Done():
180 u.errorThenClose(workspacesdk.WatchError{
181 Code: workspacesdk.WatchErrorServerShutdown,
182 Retryable: true,
183 Message: "server is shutting down",
184 })
185 return
186 case <-u.connCtx.Done():
187 return
188 case e := <-u.events:
189 if e.sync {
190 // zero this out so we'll send a full update
191 u.lastBuild = database.GetLatestWorkspaceBuildWithStatusByWorkspaceIDRow{}
192 if !u.buildUpdate() {
193 return
194 }
195 }
196 if e.wsEvent != nil {
197 switch e.wsEvent.Kind {
198 case wspubsub.WorkspaceEventKindStateChange:
199 if !u.buildUpdate() {
200 return
201 }
202 case wspubsub.WorkspaceEventKindAgentLifecycleUpdate:
203 if !u.maybeSendAgentUpdate() {
204 return
205 }
206 }
207 }
208 }
209 }
210}
211
212func (u *updater) buildUpdate() bool {
213 build, err := u.db.GetLatestWorkspaceBuildWithStatusByWorkspaceID(u.connCtx, u.workspaceID)

Callers 1

Calls 6

errorThenCloseMethod · 0.95
buildUpdateMethod · 0.95
maybeSendAgentUpdateMethod · 0.95
NewEncoderFunction · 0.92
CloseMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected