/// <summary> /// A KeepaliveMonitor when enabled will shutdown the /// node if no one is calling the keepalive endpoint /// during a certain trashold window /// </summary> public void TryStartKeepaliveMonitor() { if (this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval.TotalSeconds > 0) { this.asyncLoop = this.asyncLoopFactory.Run("ApiFeature.KeepaliveMonitor", token => { // shortened for redability KeepaliveMonitor monitor = this.apiFeatureOptions.KeepaliveMonitor; // check the trashold to trigger a shutdown if (monitor.LastBeat.Add(monitor.KeepaliveInterval) < this.fullNode.DateTimeProvider.GetUtcNow()) { this.fullNode.Dispose(); } return(Task.CompletedTask); }, this.fullNode.NodeLifetime.ApplicationStopping, repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval, startAfter: TimeSpans.Minute); } }
public void Keepalive(TimeSpan timeSpan) { this.KeepaliveMonitor = new KeepaliveMonitor { KeepaliveInterval = timeSpan }; }