(ctx context.Context, client *codersdk.Client, logger slog.Logger)
| 210 | } |
| 211 | |
| 212 | func (r *Runner) dialNotificationWebsocket(ctx context.Context, client *codersdk.Client, logger slog.Logger) (*websocket.Conn, error) { |
| 213 | u, err := client.URL.Parse("/api/v2/notifications/inbox/watch") |
| 214 | if err != nil { |
| 215 | logger.Error(ctx, "parse notification URL", slog.Error(err)) |
| 216 | r.cfg.Metrics.AddError("parse_url") |
| 217 | return nil, xerrors.Errorf("parse notification URL: %w", err) |
| 218 | } |
| 219 | |
| 220 | conn, resp, err := websocket.Dial(ctx, u.String(), &websocket.DialOptions{ |
| 221 | HTTPHeader: http.Header{ |
| 222 | "Coder-Session-Token": []string{client.SessionToken()}, |
| 223 | }, |
| 224 | }) |
| 225 | if err != nil { |
| 226 | if resp != nil { |
| 227 | defer resp.Body.Close() |
| 228 | if resp.StatusCode != http.StatusSwitchingProtocols { |
| 229 | err = codersdk.ReadBodyAsError(resp) |
| 230 | } |
| 231 | } |
| 232 | logger.Error(ctx, "dial notification websocket", slog.Error(err)) |
| 233 | r.cfg.Metrics.AddError("dial") |
| 234 | return nil, xerrors.Errorf("dial notification websocket: %w", err) |
| 235 | } |
| 236 | |
| 237 | return conn, nil |
| 238 | } |
| 239 | |
| 240 | // watchNotifications reads notifications from the websocket and returns error or nil |
| 241 | // once all expected notifications are received. |
no test coverage detected