({
config,
dashboardUrl,
apiUrl,
apiKey,
environmentClient,
projectName,
debuggerOn,
debugOtel,
configPath,
configModule,
}: DevProps)
| 248 | }; |
| 249 | |
| 250 | function useDev({ |
| 251 | config, |
| 252 | dashboardUrl, |
| 253 | apiUrl, |
| 254 | apiKey, |
| 255 | environmentClient, |
| 256 | projectName, |
| 257 | debuggerOn, |
| 258 | debugOtel, |
| 259 | configPath, |
| 260 | configModule, |
| 261 | }: DevProps) { |
| 262 | useEffect(() => { |
| 263 | const websocketUrl = new URL(apiUrl); |
| 264 | websocketUrl.protocol = websocketUrl.protocol.replace("http", "ws"); |
| 265 | websocketUrl.pathname = `/ws`; |
| 266 | |
| 267 | const websocket = new WebSocket(websocketUrl.href, [], { |
| 268 | WebSocket: WebsocketFactory(apiKey), |
| 269 | connectionTimeout: 10000, |
| 270 | maxRetries: 10, |
| 271 | minReconnectionDelay: 1000, |
| 272 | maxReconnectionDelay: 30000, |
| 273 | reconnectionDelayGrowFactor: 1.4, // This leads to the following retry times: 1, 1.4, 1.96, 2.74, 3.84, 5.38, 7.53, 10.54, 14.76, 20.66 |
| 274 | maxEnqueuedMessages: 250, |
| 275 | }); |
| 276 | |
| 277 | const sender = new ZodMessageSender({ |
| 278 | schema: clientWebsocketMessages, |
| 279 | sender: async (message) => { |
| 280 | websocket.send(JSON.stringify(message)); |
| 281 | }, |
| 282 | }); |
| 283 | |
| 284 | const backgroundWorkerCoordinator = new BackgroundWorkerCoordinator( |
| 285 | `${dashboardUrl}/projects/v3/${config.project}` |
| 286 | ); |
| 287 | |
| 288 | websocket.addEventListener("open", async (event) => {}); |
| 289 | websocket.addEventListener("close", (event) => {}); |
| 290 | websocket.addEventListener("error", (event) => {}); |
| 291 | |
| 292 | // This is the deprecated task heart beat that uses the friendly attempt ID |
| 293 | backgroundWorkerCoordinator.onWorkerTaskHeartbeat.attach( |
| 294 | async ({ worker, backgroundWorkerId, id }) => { |
| 295 | await sender.send("BACKGROUND_WORKER_MESSAGE", { |
| 296 | backgroundWorkerId, |
| 297 | data: { |
| 298 | type: "TASK_HEARTBEAT", |
| 299 | id, |
| 300 | }, |
| 301 | }); |
| 302 | } |
| 303 | ); |
| 304 | |
| 305 | // "Task Run Heartbeat" id is the actual run ID that corresponds to the MarQS message ID |
| 306 | backgroundWorkerCoordinator.onWorkerTaskRunHeartbeat.attach( |
| 307 | async ({ worker, backgroundWorkerId, id }) => { |
no test coverage detected
searching dependent graphs…