Commit 8cf0a91d authored by Dan Gershony's avatar Dan Gershony

Rename to keepalive

parent d8d9e40e
...@@ -34,30 +34,31 @@ namespace Breeze.Api ...@@ -34,30 +34,31 @@ namespace Breeze.Api
Logs.FullNode.LogInformation($"Api starting on url {this.fullNode.Settings.ApiUri}"); Logs.FullNode.LogInformation($"Api starting on url {this.fullNode.Settings.ApiUri}");
Program.Initialize(this.fullNodeBuilder.Services, this.fullNode); Program.Initialize(this.fullNodeBuilder.Services, this.fullNode);
this.TryStartHeartbeat(); this.TryStartKeepaliveMonitor();
} }
/// <summary> /// <summary>
/// A heartbeat monitor that when enabled will shutdown /// A KeepaliveMonitor when enabled will shutdown the
/// the node if no external beat was made during the trashold /// node if no one is calling the keepalive endpoint
/// during a certain trashold window
/// </summary> /// </summary>
public void TryStartHeartbeat() public void TryStartKeepaliveMonitor()
{ {
if (this.apiFeatureOptions.HeartbeatMonitor?.HeartbeatInterval.TotalSeconds > 0) if (this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval.TotalSeconds > 0)
{ {
this.asyncLoopFactory.Run("ApiFeature.MonitorHeartbeat", token => this.asyncLoopFactory.Run("ApiFeature.KeepaliveMonitor", token =>
{ {
// shortened for redability // shortened for redability
var monitor = this.apiFeatureOptions.HeartbeatMonitor; var monitor = this.apiFeatureOptions.KeepaliveMonitor;
// check the trashold to trigger a shutdown // check the trashold to trigger a shutdown
if (monitor.LastBeat.Add(monitor.HeartbeatInterval) < DateTime.UtcNow) if (monitor.LastBeat.Add(monitor.KeepaliveInterval) < DateTime.UtcNow)
this.fullNode.Stop(); this.fullNode.Stop();
return Task.CompletedTask; return Task.CompletedTask;
}, },
this.fullNode.GlobalCancellation.Cancellation.Token, this.fullNode.GlobalCancellation.Cancellation.Token,
repeatEvery: this.apiFeatureOptions.HeartbeatMonitor?.HeartbeatInterval, repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval,
startAfter: TimeSpans.Minute); startAfter: TimeSpans.Minute);
} }
} }
...@@ -65,11 +66,11 @@ namespace Breeze.Api ...@@ -65,11 +66,11 @@ namespace Breeze.Api
public class ApiFeatureOptions public class ApiFeatureOptions
{ {
public HeartbeatMonitor HeartbeatMonitor { get; set; } public KeepaliveMonitor KeepaliveMonitor { get; set; }
public void Heartbeat(TimeSpan timeSpan) public void Keepalive(TimeSpan timeSpan)
{ {
this.HeartbeatMonitor = new HeartbeatMonitor {HeartbeatInterval = timeSpan}; this.KeepaliveMonitor = new KeepaliveMonitor {KeepaliveInterval = timeSpan};
} }
} }
......
...@@ -47,17 +47,17 @@ namespace Breeze.Api.Controllers ...@@ -47,17 +47,17 @@ namespace Breeze.Api.Controllers
} }
/// <summary> /// <summary>
/// Set the hearbeat flag. /// Set the keepalive flag.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("heartbeat")] [Route("keepalive")]
public IActionResult Heartbeat() public IActionResult Keepalive()
{ {
if (this.apiFeatureOptions.HeartbeatMonitor == null) if (this.apiFeatureOptions.KeepaliveMonitor == null)
return new ObjectResult("Heartbeat Disabled") {StatusCode = 405}; // (405) Method Not Allowed return new ObjectResult("Keepalive Disabled") {StatusCode = 405}; // (405) Method Not Allowed
this.apiFeatureOptions.HeartbeatMonitor.LastBeat = DateTime.UtcNow; this.apiFeatureOptions.KeepaliveMonitor.LastBeat = DateTime.UtcNow;
return this.Ok(); return this.Ok();
} }
......
...@@ -5,9 +5,9 @@ using System.Threading.Tasks; ...@@ -5,9 +5,9 @@ using System.Threading.Tasks;
namespace Breeze.Api.Models namespace Breeze.Api.Models
{ {
public class HeartbeatMonitor public class KeepaliveMonitor
{ {
public DateTime LastBeat { get; set; } public DateTime LastBeat { get; set; }
public TimeSpan HeartbeatInterval { get; set; } public TimeSpan KeepaliveInterval { get; set; }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment