diff --git a/Giants.Services/Services/ServerRegistryCleanupService.cs b/Giants.Services/Services/ServerRegistryCleanupService.cs index cf7551c..1d760a1 100644 --- a/Giants.Services/Services/ServerRegistryCleanupService.cs +++ b/Giants.Services/Services/ServerRegistryCleanupService.cs @@ -62,7 +62,9 @@ { List expiredServers = (await this .serverRegistryStore - .GetServerInfos(whereExpression: s => s.LastHeartbeat < (this.dateTimeProvider.UtcNow - this.timeoutPeriod))) + .GetServerInfos( + whereExpression: s => s.LastHeartbeat < (this.dateTimeProvider.UtcNow - this.timeoutPeriod), + includeExpired: true)) .Select(s => s.id) .ToList(); diff --git a/Giants.Services/Store/CosmosDbServerRegistryStore.cs b/Giants.Services/Store/CosmosDbServerRegistryStore.cs index 969e7d6..f16d4b1 100644 --- a/Giants.Services/Store/CosmosDbServerRegistryStore.cs +++ b/Giants.Services/Store/CosmosDbServerRegistryStore.cs @@ -38,6 +38,7 @@ public async Task> GetServerInfos( Expression> whereExpression = null, + bool includeExpired = false, string partitionKey = null) { ConcurrentDictionary serverInfo = await this.memoryCache.GetOrCreateAsync(CacheKeys.ServerInfo, this.PopulateCache); @@ -51,12 +52,18 @@ serverInfoQuery = serverInfoQuery.Where(whereExpression); } - return serverInfoQuery.Where(c => c.LastHeartbeat > this.dateTimeProvider.UtcNow - this.timeoutPeriod) + if (!includeExpired) + { + serverInfoQuery = serverInfoQuery.Where(c => c.LastHeartbeat > this.dateTimeProvider.UtcNow - this.timeoutPeriod); + } + + return serverInfoQuery .ToList(); } public async Task> GetServerInfos( Expression> selectExpression, + bool includeExpired = false, Expression> whereExpression = null, string partitionKey = null) { @@ -71,7 +78,12 @@ serverInfoQuery = serverInfoQuery.Where(whereExpression); } - return serverInfoQuery.Where(c => c.LastHeartbeat > this.dateTimeProvider.UtcNow - this.timeoutPeriod) + if (!includeExpired) + { + serverInfoQuery = serverInfoQuery.Where(c => c.LastHeartbeat > this.dateTimeProvider.UtcNow - this.timeoutPeriod); + } + + return serverInfoQuery .Select(selectExpression) .ToList(); } diff --git a/Giants.Services/Store/IServerRegistryStore.cs b/Giants.Services/Store/IServerRegistryStore.cs index b33c3d3..9fcf522 100644 --- a/Giants.Services/Store/IServerRegistryStore.cs +++ b/Giants.Services/Store/IServerRegistryStore.cs @@ -15,10 +15,11 @@ Task GetServerInfo(string ipAddress); - Task> GetServerInfos(Expression> whereExpression = null, string partitionKey = null); + Task> GetServerInfos(Expression> whereExpression = null, bool includeExpired = false, string partitionKey = null); Task> GetServerInfos( Expression> selectExpression, + bool includeExpired = false, Expression> whereExpression = null, string partitionKey = null); diff --git a/Giants.Services/Store/InMemoryServerRegistryStore.cs b/Giants.Services/Store/InMemoryServerRegistryStore.cs index a052f3c..65c6975 100644 --- a/Giants.Services/Store/InMemoryServerRegistryStore.cs +++ b/Giants.Services/Store/InMemoryServerRegistryStore.cs @@ -36,7 +36,10 @@ return Task.CompletedTask; } - public Task> GetServerInfos(Expression> whereExpression = null, string partitionKey = null) + public Task> GetServerInfos( + Expression> whereExpression = null, + bool includeExpired = false, + string partitionKey = null) { IQueryable serverInfoQuery = this.servers.Values.AsQueryable(); @@ -48,7 +51,11 @@ return Task.FromResult(serverInfoQuery.AsEnumerable()); } - public Task> GetServerInfos(Expression> selectExpression, Expression> whereExpression = null, string partitionKey = null) + public Task> GetServerInfos( + Expression> selectExpression, + bool includeExpired = false, + Expression > whereExpression = null, + string partitionKey = null) { IQueryable serverInfoQuery = this.servers.Values.AsQueryable();