1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-21 13:45:37 +01:00

Fix heartbeats being ignored.

This commit is contained in:
Nick Blakely 2020-08-11 22:15:13 -07:00
parent e44d685d55
commit c6c9b6f4f9

View File

@ -20,6 +20,8 @@
private readonly IDateTimeProvider dateTimeProvider;
private readonly TimeSpan timeoutPeriod;
private CosmosDbClient client;
private const int ServerRefreshIntervalInMinutes = 1;
public CosmosDbServerRegistryStore(
ILogger<CosmosDbServerRegistryStore> logger,
@ -104,7 +106,12 @@
if (allServerInfo.ContainsKey(serverInfo.HostIpAddress))
{
if (allServerInfo[serverInfo.HostIpAddress].Equals(serverInfo))
ServerInfo existingServerInfo = allServerInfo[serverInfo.HostIpAddress];
// DDOS protection: skip write to Cosmos if parameters have not changed,
// or it's not been long enough.
if (existingServerInfo.Equals(serverInfo)
&& Math.Abs((existingServerInfo.LastHeartbeat - serverInfo.LastHeartbeat).TotalMinutes) < ServerRefreshIntervalInMinutes)
{
this.logger.LogInformation("State for {IPAddress} is unchanged. Skipping write to store.", serverInfo.HostIpAddress);
return;