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

Rename to keepalive

parent d8d9e40e
......@@ -34,30 +34,31 @@ namespace Breeze.Api
Logs.FullNode.LogInformation($"Api starting on url {this.fullNode.Settings.ApiUri}");
Program.Initialize(this.fullNodeBuilder.Services, this.fullNode);
this.TryStartHeartbeat();
this.TryStartKeepaliveMonitor();
}
/// <summary>
/// A heartbeat monitor that when enabled will shutdown
/// the node if no external beat was made during the trashold
/// A KeepaliveMonitor when enabled will shutdown the
/// node if no one is calling the keepalive endpoint
/// during a certain trashold window
/// </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
var monitor = this.apiFeatureOptions.HeartbeatMonitor;
var monitor = this.apiFeatureOptions.KeepaliveMonitor;
// 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();
return Task.CompletedTask;
},
this.fullNode.GlobalCancellation.Cancellation.Token,
repeatEvery: this.apiFeatureOptions.HeartbeatMonitor?.HeartbeatInterval,
repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval,
startAfter: TimeSpans.Minute);
}
}
......@@ -65,11 +66,11 @@ namespace Breeze.Api
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
}
/// <summary>
/// Set the hearbeat flag.
/// Set the keepalive flag.
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("heartbeat")]
public IActionResult Heartbeat()
[Route("keepalive")]
public IActionResult Keepalive()
{
if (this.apiFeatureOptions.HeartbeatMonitor == null)
return new ObjectResult("Heartbeat Disabled") {StatusCode = 405}; // (405) Method Not Allowed
if (this.apiFeatureOptions.KeepaliveMonitor == null)
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();
}
......
......@@ -5,9 +5,9 @@ using System.Threading.Tasks;
namespace Breeze.Api.Models
{
public class HeartbeatMonitor
public class KeepaliveMonitor
{
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