Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace ServiceControl.Persistence.EFCore.Implementation;

public class EndpointSettingsStore : IEndpointSettingsStore
{
public IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings() =>
public IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings(CancellationToken cancellationToken) =>
throw new NotImplementedException();

public Task UpdateEndpointSettings(EndpointSettings settings, CancellationToken token) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ServiceControl.Persistence.RavenDB;

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure;
Expand All @@ -12,14 +13,14 @@ class EndpointSettingsStore(IRavenSessionProvider sessionProvider) : IEndpointSe
static string MakeDocumentId(string name) =>
$"{EndpointSettings.CollectionName}/{DeterministicGuid.MakeId(name)}";

public async IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings()
public async IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings([EnumeratorCancellation] CancellationToken cancellationToken)
{
using IAsyncDocumentSession session = await sessionProvider.OpenSession();
using IAsyncDocumentSession session = await sessionProvider.OpenSession(cancellationToken: cancellationToken);
await using IAsyncEnumerator<StreamResult<EndpointSettings>> enumerator = await session
.Advanced
.StreamAsync<EndpointSettings>($"{EndpointSettings.CollectionName}/");
.StreamAsync<EndpointSettings>($"{EndpointSettings.CollectionName}/", token: cancellationToken);

while (await enumerator.MoveNextAsync())
while (await enumerator.MoveNextAsync() && !cancellationToken.IsCancellationRequested)
{
yield return enumerator.Current.Document;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControl.Persistence/IEndpointSettingsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface IEndpointSettingsStore
{
IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings();
IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings(CancellationToken token);

Task UpdateEndpointSettings(EndpointSettings settings, CancellationToken token);
Task Delete(string name, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void RecordHeartbeat(EndpointInstanceId endpointInstanceId, DateTime time

class MockEndpointSettingsStore(EndpointSettings[] settings) : IEndpointSettingsStore
{
public IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings() => settings.ToAsyncEnumerable();
public IAsyncEnumerable<EndpointSettings> GetAllEndpointSettings(CancellationToken token) => settings.ToAsyncEnumerable();

public Task UpdateEndpointSettings(EndpointSettings settings, CancellationToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ async Task PurgeMonitoringDataThatDoesNotNeedToBeTracked(CancellationToken cance
ILookup<string, Guid> monitorEndpointsLookup = endpointsViews
.Where(view => !view.IsSendingHeartbeats)
.ToLookup(view => view.Name, view => view.Id);
await foreach (EndpointSettings endpointSetting in endpointSettingsStore.GetAllEndpointSettings()
.WithCancellation(cancellationToken))
await foreach (EndpointSettings endpointSetting in endpointSettingsStore.GetAllEndpointSettings(cancellationToken))
{
if (!endpointSetting.TrackInstances)
{
Expand All @@ -94,8 +93,7 @@ async Task InitialiseSettings(HashSet<string> monitorEndpoints, CancellationToke
HashSet<string> settingsNames = [];

// Delete any endpoints data that no longer exists
await foreach (EndpointSettings endpointSetting in endpointSettingsStore.GetAllEndpointSettings()
.WithCancellation(cancellationToken))
await foreach (EndpointSettings endpointSetting in endpointSettingsStore.GetAllEndpointSettings(cancellationToken))
{
if (endpointSetting.Name == string.Empty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class EndpointsSettingsController(
public async IAsyncEnumerable<SettingsData> Endpoints([EnumeratorCancellation] CancellationToken token)
{
await using IAsyncEnumerator<EndpointSettings> enumerator =
dataStore.GetAllEndpointSettings().GetAsyncEnumerator(token);
dataStore.GetAllEndpointSettings(token).GetAsyncEnumerator(token);
bool noResults = true;
while (await enumerator.MoveNextAsync())
{
Expand Down
Loading