Skip to content

Commit

Permalink
Merge pull request #236 from EgdeConsulting/235-remove-temporary-cons…
Browse files Browse the repository at this point in the history
…umers-from-stream-page

GH-235: Added filtering of consumers.
  • Loading branch information
TobiasGunther authored Apr 29, 2023
2 parents 6669053 + a8f8753 commit 03caac4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/vite-api/Classes/StreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<BasicStreamInfoDto> GetAllStreams()
{
Name = x.Config.Name,
SubjectCount = x.State.SubjectCount,
ConsumerCount = x.State.ConsumerCount,
ConsumerCount = FilterConsumers(jsm.GetConsumers(x.Config.Name).ToList()).Count,
MessageCount = x.State.Messages
}).ToList();
}
Expand All @@ -76,7 +76,7 @@ public ExtendedStreamInfoDto GetSpecificStream(string streamName)
{
Name = streamInfo.Config.Name,
Subjects = streamInfo.Config.Subjects,
Consumers = jsm.GetConsumerNames(streamName).ToList(),
Consumers = FilterConsumers(jsm.GetConsumers(streamName).ToList()).Select(x => x.Name).ToList(),
Description = streamInfo.Config.Description,
Messages = streamInfo.State.Messages,
Deleted = streamInfo.State.DeletedCount,
Expand All @@ -92,5 +92,18 @@ public ExtendedStreamInfoDto GetSpecificStream(string streamName)
throw new ArgumentException("Given stream name or sequence number does not exist on the server");
}
}

/// <summary>
/// Filters consumers based on the date they where created. Only consumers older than 10 minutes are being kept.
/// </summary>
/// <param name="consumers">List of consumers.</param>
/// <returns>Filtered list.</returns>
private static List<ConsumerInfo> FilterConsumers(IEnumerable<ConsumerInfo> consumers)
{
return consumers.Where(x =>
DateTime.Now.Date > x.Created ||
(DateTime.Now.ToUniversalTime() - x.Created.ToUniversalTime()).TotalHours >= 1 ||
(DateTime.Now.ToUniversalTime() - x.Created.ToUniversalTime()).TotalMinutes > 10).ToList();
}
}
}

0 comments on commit 03caac4

Please sign in to comment.