| 406 | } |
| 407 | |
| 408 | const dispatchWake: RuntimeRouter[`dispatchWake`] = ( |
| 409 | notification, |
| 410 | options |
| 411 | ): void => { |
| 412 | const wakeLabel = notification.streamPath |
| 413 | const controller = new AbortController() |
| 414 | const wake: Promise<void> = Promise.resolve( |
| 415 | processWake(notification, { |
| 416 | ...wakeConfig, |
| 417 | ...options, |
| 418 | shutdownSignal: controller.signal, |
| 419 | }) |
| 420 | ) |
| 421 | .then(() => undefined) |
| 422 | .catch((err: unknown) => { |
| 423 | const wakeError = err instanceof Error ? err : new Error(String(err)) |
| 424 | const handled = config.onWakeError?.(wakeError) === true |
| 425 | if (!handled) { |
| 426 | wakeErrors.push(wakeError) |
| 427 | } |
| 428 | runtimeLog.error( |
| 429 | `[agent-runtime]`, |
| 430 | `Error processing wake for ${notification.entity?.url}:`, |
| 431 | wakeError |
| 432 | ) |
| 433 | }) |
| 434 | .finally(() => { |
| 435 | pendingWakes.delete(wake) |
| 436 | pendingWakeLabels.delete(wake) |
| 437 | pendingWakeControllers.delete(wake) |
| 438 | }) |
| 439 | pendingWakes.add(wake) |
| 440 | pendingWakeLabels.set(wake, wakeLabel) |
| 441 | pendingWakeControllers.set(wake, controller) |
| 442 | } |
| 443 | |
| 444 | const isWakeActive: RuntimeRouter[`isWakeActive`] = (streamPath) => |
| 445 | [...pendingWakeLabels.values()].includes(streamPath) |