UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

53 lines (51 loc) 1.77 kB
import { ConnectMessage, GatewayMessageType, WorkerStatusData } from "../../../../proto/src/components/connect/protobuf/connect.js"; import { ensureUnsharedArrayBuffer } from "../../buffer.js"; //#region src/components/connect/strategies/core/statusReporter.ts var StatusReporter = class { interval; intervalMs = 0; constructor(accessor, logger) { this.accessor = accessor; this.logger = logger; } /** * Update the status reporting interval. Restarts the timer if the interval * changed or if it wasn't running yet. A value of 0 disables reporting. */ updateInterval(ms) { if (ms === this.intervalMs && (this.interval || ms === 0)) return; this.intervalMs = ms; this.stop(); if (ms > 0) this.start(); } /** Stop the status reporting timer. */ stop() { clearInterval(this.interval); this.interval = void 0; } start() { if (this.interval) return; this.interval = setInterval(() => this.tick(), this.intervalMs); } tick() { const conn = this.accessor.activeConnection; if (!conn || conn.ws.readyState !== WebSocket.OPEN) return; const inFlightRequestIds = Object.keys(this.accessor.inProgressRequests.requestLeases); const statusPayload = WorkerStatusData.encode(WorkerStatusData.create({ inFlightRequestIds, shutdownRequested: this.accessor.shutdownRequested })).finish(); conn.ws.send(ensureUnsharedArrayBuffer(ConnectMessage.encode(ConnectMessage.create({ kind: GatewayMessageType.WORKER_STATUS, payload: statusPayload })).finish())); this.logger.debug({ connectionId: conn.id, inFlightRequestCount: inFlightRequestIds.length, shutdownRequested: this.accessor.shutdownRequested }, "Worker status sent"); } }; //#endregion export { StatusReporter }; //# sourceMappingURL=statusReporter.js.map