Class ConnectionHeartbeatService
- Namespace
- Virtufin.WebSocketManager.Services
- Assembly
- Virtufin.WebSocketManager.dll
Periodically refreshes the state-store TTL, and pings the owning actor,
for 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." The same gap applies to
WebSocketConnectionActor's Dapr idle timer -- a
receive-only connection never invokes any other actor method, so the
periodic TouchAsync call here is what keeps it from being
idle-deactivated while its socket is still open (see that class's doc
comment).
public sealed class ConnectionHeartbeatService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
ConnectionHeartbeatService
- Implements
- Inherited Members
Constructors
ConnectionHeartbeatService(IWebSocketConnectionStore, IActorProxyFactory, ConnectionStoreOptions, ILogger<ConnectionHeartbeatService>)
public ConnectionHeartbeatService(IWebSocketConnectionStore connectionStore, IActorProxyFactory actorProxies, ConnectionStoreOptions options, ILogger<ConnectionHeartbeatService> logger)
Parameters
connectionStoreIWebSocketConnectionStoreactorProxiesIActorProxyFactoryoptionsConnectionStoreOptionsloggerILogger<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.