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

Method handleEvent

coderd/workspaceupdates.go:60–96  ·  view source on GitHub ↗
(ctx context.Context, event wspubsub.WorkspaceEvent, err error)

Source from the content-addressed store, hash-verified

58}
59
60func (s *sub) handleEvent(ctx context.Context, event wspubsub.WorkspaceEvent, err error) {
61 s.mu.Lock()
62 defer s.mu.Unlock()
63
64 switch event.Kind {
65 case wspubsub.WorkspaceEventKindStateChange:
66 case wspubsub.WorkspaceEventKindAgentConnectionUpdate:
67 case wspubsub.WorkspaceEventKindAgentTimeout:
68 case wspubsub.WorkspaceEventKindAgentLifecycleUpdate:
69 default:
70 if err == nil {
71 return
72 }
73 // Always attempt an update if the pubsub lost connection
74 s.logger.Warn(ctx, "failed to handle workspace event", slog.Error(err))
75 }
76
77 // Use context containing actor
78 rows, err := s.db.GetWorkspacesAndAgentsByOwnerID(s.ctx, s.userID)
79 if err != nil {
80 s.logger.Warn(ctx, "failed to get workspaces and agents by owner ID", slog.Error(err))
81 return
82 }
83 latest := convertRows(rows)
84
85 out, updated := produceUpdate(s.prev, latest)
86 if !updated {
87 return
88 }
89
90 s.prev = latest
91 select {
92 case <-s.ctx.Done():
93 return
94 case s.ch <- out:
95 }
96}
97
98func (s *sub) start(ctx context.Context) (err error) {
99 rows, err := s.db.GetWorkspacesAndAgentsByOwnerID(ctx, s.userID)

Callers 1

wrappedFunction · 0.45

Calls 7

convertRowsFunction · 0.85
produceUpdateFunction · 0.85
LockMethod · 0.45
UnlockMethod · 0.45
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected