Class ConnectionHeartbeatService
- Namespace
- Virtufin.WebSocketManager.Services
- Assembly
- Virtufin.WebSocketManager.dll
Periodically refreshes the state-store TTL on every locally-owned,
connected WebSocket. The connection record's TTL was previously only
refreshed by SendAsync(string, byte[], int, string, CancellationToken)/SendRawAsync
(traffic pushed to the socket) or by StartPublish/StopPublish -- a
connection that is only receiving (the common case: subscribe once,
then relay inbound messages to pub/sub) never touched its own record,
so it deterministically expired from the state store ~TTL after the
last StartPublish, independent of whether the socket was still alive.
This heartbeat makes "record TTL" track "is the socket open on this
pod" instead of "did traffic happen to flow through the touch paths."
public sealed class ConnectionHeartbeatService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
ConnectionHeartbeatService
- Implements
- Inherited Members
Constructors
ConnectionHeartbeatService(IWebSocketConnectionStore, ConnectionStoreOptions, ILogger<ConnectionHeartbeatService>)
public ConnectionHeartbeatService(IWebSocketConnectionStore connectionStore, ConnectionStoreOptions options, ILogger<ConnectionHeartbeatService> logger)
Parameters
connectionStoreIWebSocketConnectionStoreoptionsConnectionStoreOptionsloggerILogger<ConnectionHeartbeatService>
Methods
ExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.