Part of #727.
Move the duplicated heartbeat/liveness logic from the postgres and mongodb
adapters into socketioxide_core behind the existing remote-adapter feature
flag, so it can be shared by each adapter.
Current state:
socketioxide-postgres and socketioxide-mongodb each define the same
nodes_liveness: Mutex<Vec<(Uid, Instant)>> field, the same interval-based
heartbeat_job, the same emit_heartbeat/emit_init_heartbeat helpers, the
same recv_heartbeat handler (~130 LOC duplicated verbatim, only the error
type differs) and the same server_count dead-node pruning.
- The wire protocol already lives in core:
RequestTypeOut/In::Heartbeat (20)
and InitHeartbeat (21) in crates/socketioxide-core/src/adapter/remote_packet.rs.
- Redis is unaffected: it has no heartbeat (liveness is pub/sub subscriber
counting via num_serv).
Proposed shared API (sketch, in core behind remote-adapter):
HeartbeatTracker: wraps nodes_liveness + hb_timeout; on_heartbeat(origin)
(update-or-push, returns whether an InitHeartbeat reply is due), server_count()
(prune dead nodes + self), is_alive(uid).
HeartbeatSender trait: uid(), send_req(...), with default
emit_heartbeat/emit_init_heartbeat implementations.
heartbeat_loop(interval, emit) helper and a default recv_heartbeat.
Postgres and mongodb then keep only a thin adapter: a HeartbeatTracker field
plus a small HeartbeatSender impl. No behavior or wire-format change.
Part of #727.
Move the duplicated heartbeat/liveness logic from the postgres and mongodb
adapters into
socketioxide_corebehind the existingremote-adapterfeatureflag, so it can be shared by each adapter.
Current state:
socketioxide-postgresandsocketioxide-mongodbeach define the samenodes_liveness: Mutex<Vec<(Uid, Instant)>>field, the same interval-basedheartbeat_job, the sameemit_heartbeat/emit_init_heartbeathelpers, thesame
recv_heartbeathandler (~130 LOC duplicated verbatim, only the errortype differs) and the same
server_countdead-node pruning.RequestTypeOut/In::Heartbeat(20)and
InitHeartbeat(21) incrates/socketioxide-core/src/adapter/remote_packet.rs.counting via
num_serv).Proposed shared API (sketch, in core behind
remote-adapter):HeartbeatTracker: wrapsnodes_liveness+hb_timeout;on_heartbeat(origin)(update-or-push, returns whether an InitHeartbeat reply is due),
server_count()(prune dead nodes + self),
is_alive(uid).HeartbeatSendertrait:uid(),send_req(...), with defaultemit_heartbeat/emit_init_heartbeatimplementations.heartbeat_loop(interval, emit)helper and a defaultrecv_heartbeat.Postgres and mongodb then keep only a thin adapter: a
HeartbeatTrackerfieldplus a small
HeartbeatSenderimpl. No behavior or wire-format change.