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

Fix expired servers not being cleaned up.

This commit is contained in:
Nick Blakely 2020-08-16 01:47:25 -07:00
parent 66b9ff5704
commit 2159bbc8b9
4 changed files with 28 additions and 6 deletions

View File

@ -62,7 +62,9 @@
{
List<string> 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();

View File

@ -38,6 +38,7 @@
public async Task<IEnumerable<ServerInfo>> GetServerInfos(
Expression<Func<ServerInfo, bool>> whereExpression = null,
bool includeExpired = false,
string partitionKey = null)
{
ConcurrentDictionary<string, ServerInfo> 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<IEnumerable<TSelect>> GetServerInfos<TSelect>(
Expression<Func<ServerInfo, TSelect>> selectExpression,
bool includeExpired = false,
Expression<Func<ServerInfo, bool>> 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();
}

View File

@ -15,10 +15,11 @@
Task<ServerInfo> GetServerInfo(string ipAddress);
Task<IEnumerable<ServerInfo>> GetServerInfos(Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null);
Task<IEnumerable<ServerInfo>> GetServerInfos(Expression<Func<ServerInfo, bool>> whereExpression = null, bool includeExpired = false, string partitionKey = null);
Task<IEnumerable<TSelect>> GetServerInfos<TSelect>(
Expression<Func<ServerInfo, TSelect>> selectExpression,
bool includeExpired = false,
Expression<Func<ServerInfo, bool>> whereExpression = null,
string partitionKey = null);

View File

@ -36,7 +36,10 @@
return Task.CompletedTask;
}
public Task<IEnumerable<ServerInfo>> GetServerInfos(Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null)
public Task<IEnumerable<ServerInfo>> GetServerInfos(
Expression<Func<ServerInfo, bool>> whereExpression = null,
bool includeExpired = false,
string partitionKey = null)
{
IQueryable<ServerInfo> serverInfoQuery = this.servers.Values.AsQueryable();
@ -48,7 +51,11 @@
return Task.FromResult(serverInfoQuery.AsEnumerable());
}
public Task<IEnumerable<TSelect>> GetServerInfos<TSelect>(Expression<Func<ServerInfo, TSelect>> selectExpression, Expression<Func<ServerInfo, bool>> whereExpression = null, string partitionKey = null)
public Task<IEnumerable<TSelect>> GetServerInfos<TSelect>(
Expression<Func<ServerInfo, TSelect>> selectExpression,
bool includeExpired = false,
Expression <Func<ServerInfo, bool>> whereExpression = null,
string partitionKey = null)
{
IQueryable<ServerInfo> serverInfoQuery = this.servers.Values.AsQueryable();