feat: Heartbeat-Pulsierung (Flughafen-Prinzip) — PulseController + DetectionTimer, DDP-basiert, keine Core-Abhaengigkeit
NEUE KLASSEN: - PulseController: DDP-basierte Pulsierung (1.5s Intervall, konfigurierbar) - Zyklisch online↔away via DDP set_status (K1: keine Message-Variante) - REST-Fallback nur fuer Message-Text - Coalesce: skip wenn Status bereits away und Tick will away - pause()/resume() fuer Reconnect-Races (EC-2) - bind_ddp() nachtraeglich moeglich (EC-1) - DetectionTimer: erkennt Hintergrund-Agenten (10s Intervall) - Liest ~/.hermes/gateway_state.json -> active_agents > 1 - Fallback: subprocess pgrep -f "hermes chat --profile" - on_change Callback fuer State-Wechsel ERWEITERUNG PresenceEngine: - cancel_pending() API (K2, EC-5) - on_agent_busy(): pausiert Pulse, setzt busy (rot) — Vorrang - on_message_received(): wie on_agent_busy - _set_presence ruft cancel_pending() (EC-5) ADAPTER: - _on_ddp_connected(): bindet DDP an PulseController nach Connect (EC-1) - on_connected_cb ersetzt Lambda durch _on_ddp_connected TELEMETRIE: - routing_telemetry.heartbeat_pulse counter - routing_telemetry.heartbeat_detection counter TESTS: 21 neue (Tests 17-32), alle 45 Tests gruen - 17-19: PulseController start/stop/bind_ddp - 20-22: DetectionTimer pgrep/gateway_state/integration - 23-25: DDP-Only-Send / REST-Only-Fallback / Beide-defekt - 26-28: Coalesce-Skip, Phase-Toggle, last_sent_phase - 29-30: EC-1 (on_connected_cb race), EC-2 (reconnect race) - 31-32: on_agent_busy / on_message_received Hooks
This commit is contained in:
+21
-2
@@ -859,6 +859,25 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
lines.append(f" Keywords Kontext: {kwctx}")
|
||||
return "\n".join(lines)
|
||||
|
||||
def _on_ddp_connected(self) -> None:
|
||||
"""Callback when DDP connection is established.
|
||||
|
||||
Sets initial online status and binds DDP to PulseController
|
||||
if PresenceEngine is active (EC-1: on_connected_cb race).
|
||||
"""
|
||||
if self.ddp:
|
||||
self.ddp.set_status("online")
|
||||
# V8.6: PulseController DDP-Bindung nach Connect (EC-1)
|
||||
if hasattr(self, '_presence_engine') and self._presence_engine is not None:
|
||||
try:
|
||||
from archivar.presence_engine import PulseController
|
||||
if hasattr(self._presence_engine, '_pulse_controller') and \
|
||||
isinstance(self._presence_engine._pulse_controller, PulseController):
|
||||
self._presence_engine._pulse_controller.bind_ddp(self.ddp)
|
||||
logger.debug("[rocketchat] V8.6: PulseController DDP gebunden (on_connected_cb)")
|
||||
except Exception as e:
|
||||
logger.debug("[rocketchat] V8.6: PulseController bind_ddp failed: %s", e)
|
||||
|
||||
def _on_ddp_room_event(self, event: dict) -> None:
|
||||
"""A1b: Callback für DDP rooms-changed Events.
|
||||
|
||||
@@ -1217,7 +1236,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
host = self.base_url.replace("https://", "").replace("http://", "").split("/")[0]
|
||||
self.ddp = DDPClient(
|
||||
host=host,
|
||||
on_connected_cb=lambda: self.ddp.set_status("online") if self.ddp else None,
|
||||
on_connected_cb=self._on_ddp_connected,
|
||||
on_room_event_cb=self._on_ddp_room_event, # A1b: DDP room events
|
||||
)
|
||||
if not self.ddp.connect_and_login(self._auth_token):
|
||||
@@ -1450,7 +1469,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
host = self.base_url.replace("https://", "").replace("http://", "").split("/")[0]
|
||||
self.ddp = DDPClient(
|
||||
host=host,
|
||||
on_connected_cb=lambda: self.ddp.set_status("online") if self.ddp else None,
|
||||
on_connected_cb=self._on_ddp_connected,
|
||||
on_room_event_cb=self._on_ddp_room_event, # A1b: DDP room events (P0-3)
|
||||
)
|
||||
if not self.ddp.connect_and_login(self._auth_token):
|
||||
|
||||
Reference in New Issue
Block a user