MCPcopy Create free account
hub / github.com/tiann/hapi / handleMachineAlive

Method handleMachineAlive

hub/src/sync/machineCache.ts:111–129  ·  view source on GitHub ↗
(payload: { machineId: string; time: number })

Source from the content-addressed store, hash-verified

109 }
110
111 handleMachineAlive(payload: { machineId: string; time: number }): void {
112 const t = clampAliveTime(payload.time)
113 if (!t) return
114
115 const machine = this.machines.get(payload.machineId) ?? this.refreshMachine(payload.machineId)
116 if (!machine) return
117
118 const wasActive = machine.active
119 machine.active = true
120 machine.activeAt = Math.max(machine.activeAt, t)
121
122 const now = Date.now()
123 const lastBroadcastAt = this.lastBroadcastAtByMachineId.get(machine.id) ?? 0
124 const shouldBroadcast = (!wasActive && machine.active) || (now - lastBroadcastAt > 10_000)
125 if (shouldBroadcast) {
126 this.lastBroadcastAtByMachineId.set(machine.id, now)
127 this.publisher.emit({ type: 'machine-updated', machineId: machine.id, data: machine })
128 }
129 }
130
131 expireInactive(now: number = Date.now()): void {
132 const machineTimeoutMs = 45_000

Callers

nothing calls this directly

Calls 4

refreshMachineMethod · 0.95
clampAliveTimeFunction · 0.90
getMethod · 0.80
emitMethod · 0.45

Tested by

no test coverage detected