MCPcopy Index your code
hub / github.com/upstash/jstack / createHeartbeat

Method createHeartbeat

packages/jstack-shared/src/socket.ts:109–134  ·  view source on GitHub ↗
(room: string)

Source from the content-addressed store, hash-verified

107 }
108
109 private createHeartbeat(room: string) {
110 const heartbeat = {
111 sender: setInterval(async () => {
112
113 await fetch(`${this.redisUrl}/publish/${room}`, {
114 method: 'POST',
115 headers: {
116 'Authorization': `Bearer ${this.redisToken}`,
117 'Content-Type': 'application/json'
118 },
119 body: JSON.stringify(["ping", null])
120 })
121 }, 30000),
122
123 monitor: setInterval(() => {
124 const lastPingTime = this.lastPingTimes.get(room) ?? 0
125
126 if (Date.now() - lastPingTime > 45000) {
127 logger.warn("Heartbeat timeout detected")
128 this.unsubscribe(room).then(() => this.subscribe(room))
129 }
130 }, 5000),
131 }
132
133 this.heartbeatTimers.set(room, heartbeat)
134 }
135
136 private async subscribe(room: string): Promise<void> {
137 return new Promise(async (resolve, reject) => {

Callers 1

joinMethod · 0.95

Calls 3

unsubscribeMethod · 0.95
subscribeMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected