(ctx context.Context)
| 96 | } |
| 97 | |
| 98 | func (s *sub) start(ctx context.Context) (err error) { |
| 99 | rows, err := s.db.GetWorkspacesAndAgentsByOwnerID(ctx, s.userID) |
| 100 | if err != nil { |
| 101 | return xerrors.Errorf("get workspaces and agents by owner ID: %w", err) |
| 102 | } |
| 103 | |
| 104 | latest := convertRows(rows) |
| 105 | initUpdate, _ := produceUpdate(workspacesByID{}, latest) |
| 106 | s.ch <- initUpdate |
| 107 | s.prev = latest |
| 108 | |
| 109 | cancel, err := s.ps.SubscribeWithErr(wspubsub.WorkspaceEventChannel(s.userID), wspubsub.HandleWorkspaceEvent(s.handleEvent)) |
| 110 | if err != nil { |
| 111 | return xerrors.Errorf("subscribe to workspace event channel: %w", err) |
| 112 | } |
| 113 | |
| 114 | s.psCancelFn = cancel |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | func (s *sub) Close() error { |
| 119 | s.cancelFn() |
no test coverage detected