From ade4649891ba67a5fb8078f67b23d935a91a5d7f Mon Sep 17 00:00:00 2001 From: John Simons Date: Tue, 11 Aug 2026 22:18:01 +1000 Subject: [PATCH] Propagate cancellation tokens through custom checks, event log and message redirects This change continues the effort to consistently apply optional `CancellationToken` parameters to asynchronous methods within the `ICustomChecksDataStore`, `IEventLogDataStore` and `IMessageRedirectsDataStore` interfaces, their EFCore and RavenDB implementations, and the controllers, handlers and services that consume them. Cancellation tokens are now propagated to the underlying asynchronous database calls, ensuring proper cancellation of long-running operations and further reducing cancellation analyzer debt. No `.editorconfig` suppressions are removed here, because every rule in these projects still has violations from the interface groups that remain. --- .../Implementation/CustomCheckDataStore.cs | 13 +++++---- .../Implementation/EventLogDataStore.cs | 10 +++---- .../MessageRedirectsDataStore.cs | 16 +++++----- .../EventLogDataStore.cs | 16 +++++----- .../MessageRedirectsDataStore.cs | 23 ++++++++------- .../RavenCustomCheckDataStore.cs | 29 ++++++++++--------- .../ICustomChecksDataStore.cs | 9 +++--- .../IEventLogDataStore.cs | 5 ++-- .../IMessageRedirectsDataStore.cs | 9 +++--- .../CustomCheckResultProcessor.cs | 4 +-- .../CustomChecks/DeleteCustomCheckHandler.cs | 2 +- .../CustomChecks/Web/CustomCheckController.cs | 2 +- .../EventLog/AuditEventLogWriter.cs | 2 +- .../EventLog/EventLogApiController.cs | 2 +- .../Api/MessageRedirectsController.cs | 16 +++++----- .../Recoverability/Editing/EditHandler.cs | 2 +- .../Recoverability/Retrying/RetryProcessor.cs | 2 +- 17 files changed, 85 insertions(+), 77 deletions(-) diff --git a/src/ServiceControl.Persistence.EFCore/Implementation/CustomCheckDataStore.cs b/src/ServiceControl.Persistence.EFCore/Implementation/CustomCheckDataStore.cs index 78ed1752cd..182830bd92 100644 --- a/src/ServiceControl.Persistence.EFCore/Implementation/CustomCheckDataStore.cs +++ b/src/ServiceControl.Persistence.EFCore/Implementation/CustomCheckDataStore.cs @@ -8,7 +8,7 @@ namespace ServiceControl.Persistence.EFCore.Implementation; public class CustomCheckDataStore(IServiceScopeFactory scopeFactory) : DataStoreBase(scopeFactory), ICustomChecksDataStore { - public Task UpdateCustomCheckStatus(CustomCheckDetail detail) => ExecuteWithDbContext(async context => + public Task UpdateCustomCheckStatus(CustomCheckDetail detail, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => { var status = CheckStateChange.Unchanged; @@ -43,11 +43,12 @@ await context.UpsertAsync([detail.GetDeterministicId()], entity.Category = detail.Category; entity.ReportedAt = detail.ReportedAt; entity.FailureReason = detail.FailureReason; - }); + }, + cancellationToken); return status; }); - public Task>> GetStats(PagingInfo paging, string? status = null) => ExecuteWithDbContext(async context => + public Task>> GetStats(PagingInfo paging, string? status = null, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => { var query = context.CustomChecks.AsQueryable().AsNoTracking(); @@ -62,7 +63,7 @@ public Task>> GetStats(PagingInfo paging, string? .OrderBy(c => c.ReportedAt) .Skip(paging.Offset) .Take(paging.PageSize) - .ToListAsync(); + .ToListAsync(cancellationToken); return new QueryResult>(page.Select(c => new CustomCheck { @@ -75,7 +76,7 @@ public Task>> GetStats(PagingInfo paging, string? }).ToList(), new QueryStatsInfo("", page.Count, false)); }); - public Task DeleteCustomCheck(Guid id) => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().Where(cc => cc.Id == id).ExecuteDeleteAsync()); + public Task DeleteCustomCheck(Guid id, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().Where(cc => cc.Id == id).ExecuteDeleteAsync(cancellationToken)); - public Task GetNumberOfFailedChecks() => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().CountAsync(p => p.Status == Status.Fail)); + public Task GetNumberOfFailedChecks(CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().CountAsync(p => p.Status == Status.Fail, cancellationToken)); } diff --git a/src/ServiceControl.Persistence.EFCore/Implementation/EventLogDataStore.cs b/src/ServiceControl.Persistence.EFCore/Implementation/EventLogDataStore.cs index 11f8475337..f7403c7ff4 100644 --- a/src/ServiceControl.Persistence.EFCore/Implementation/EventLogDataStore.cs +++ b/src/ServiceControl.Persistence.EFCore/Implementation/EventLogDataStore.cs @@ -8,7 +8,7 @@ namespace ServiceControl.Persistence.EFCore.Implementation; public class EventLogDataStore(IServiceScopeFactory scopeFactory) : DataStoreBase(scopeFactory), IEventLogDataStore { - public Task Add(EventLogItem logItem) => + public Task Add(EventLogItem logItem, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async dbContext => { dbContext.EventLogItems.Add(new EventLogItemEntity @@ -21,11 +21,11 @@ public Task Add(EventLogItem logItem) => EventType = logItem.EventType }); - await dbContext.SaveChangesAsync(); + await dbContext.SaveChangesAsync(cancellationToken); }); public Task>> GetEventLogItems( - PagingInfo pagingInfo, string? knownVersion = null) => + PagingInfo pagingInfo, string? knownVersion = null, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async dbContext => { var query = dbContext.EventLogItems.AsNoTracking(); @@ -40,7 +40,7 @@ public Task>> GetEventLogItems( Newest = g.Max(e => (DateTime?)e.RaisedAt), HighestId = g.Max(e => (long?)e.Id) }) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); var total = stats?.Total ?? 0; var version = Version(total, stats?.Newest, stats?.HighestId); @@ -71,7 +71,7 @@ public Task>> GetEventLogItems( Category = e.Category, EventType = e.EventType }) - .ToListAsync(); + .ToListAsync(cancellationToken); return new QueryResult>(items, queryStats); }); diff --git a/src/ServiceControl.Persistence.EFCore/Implementation/MessageRedirectsDataStore.cs b/src/ServiceControl.Persistence.EFCore/Implementation/MessageRedirectsDataStore.cs index cca67bb3a7..49ebd23bca 100644 --- a/src/ServiceControl.Persistence.EFCore/Implementation/MessageRedirectsDataStore.cs +++ b/src/ServiceControl.Persistence.EFCore/Implementation/MessageRedirectsDataStore.cs @@ -7,12 +7,12 @@ namespace ServiceControl.Persistence.EFCore.Implementation; public class MessageRedirectsDataStore(IServiceScopeFactory scopeFactory) : DataStoreBase(scopeFactory), IMessageRedirectsDataStore { - public Task> GetRedirects() => + public Task> GetRedirects(CancellationToken cancellationToken = default) => ExecuteWithDbContext>(async dbContext => { var rows = await dbContext.MessageRedirects .AsNoTracking() - .ToListAsync(); + .ToListAsync(cancellationToken); return [.. rows.Select(row => new MessageRedirect { @@ -22,7 +22,7 @@ public Task> GetRedirects() => })]; }); - public Task AddRedirect(MessageRedirect redirect) => + public Task AddRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async dbContext => { dbContext.MessageRedirects.Add(new MessageRedirectEntity @@ -32,18 +32,18 @@ public Task AddRedirect(MessageRedirect redirect) => LastModified = redirect.LastModified }); - await dbContext.SaveChangesAsync(); + await dbContext.SaveChangesAsync(cancellationToken); }); - public Task UpdateRedirect(MessageRedirect redirect) => + public Task UpdateRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => ExecuteWithDbContext(dbContext => dbContext.MessageRedirects .Where(row => row.FromPhysicalAddress == redirect.FromPhysicalAddress) .ExecuteUpdateAsync(setters => setters .SetProperty(row => row.ToPhysicalAddress, redirect.ToPhysicalAddress) - .SetProperty(row => row.LastModified, redirect.LastModified))); + .SetProperty(row => row.LastModified, redirect.LastModified), cancellationToken)); - public Task RemoveRedirect(MessageRedirect redirect) => + public Task RemoveRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => ExecuteWithDbContext(dbContext => dbContext.MessageRedirects .Where(row => row.FromPhysicalAddress == redirect.FromPhysicalAddress) - .ExecuteDeleteAsync()); + .ExecuteDeleteAsync(cancellationToken)); } diff --git a/src/ServiceControl.Persistence.RavenDB/EventLogDataStore.cs b/src/ServiceControl.Persistence.RavenDB/EventLogDataStore.cs index 656fb45b04..e02ae48522 100644 --- a/src/ServiceControl.Persistence.RavenDB/EventLogDataStore.cs +++ b/src/ServiceControl.Persistence.RavenDB/EventLogDataStore.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using EventLog; using Persistence.Infrastructure; @@ -9,33 +10,34 @@ class EventLogDataStore(IRavenSessionProvider sessionProvider, ExpirationManager expirationManager) : IEventLogDataStore { - public async Task Add(EventLogItem logItem) + public async Task Add(EventLogItem logItem, CancellationToken cancellationToken = default) { - using var session = await sessionProvider.OpenSession(); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); // Version 7 rather than a random GUID so the final segment is time-ordered, which keeps // documents written together adjacent in the id index. await session.StoreAsync( logItem, - EventLogItemIdGenerator.MakeDocumentId(logItem.Category, logItem.EventType, Guid.CreateVersion7())); + EventLogItemIdGenerator.MakeDocumentId(logItem.Category, logItem.EventType, Guid.CreateVersion7()), + cancellationToken); // Retention on RavenDB is per-document expiry metadata stamped at write time, not a // sweep. It has to be set here, on the only write path, or items never expire. expirationManager.EnableExpiration(session, logItem); - await session.SaveChangesAsync(); + await session.SaveChangesAsync(cancellationToken); } public async Task>> GetEventLogItems( - PagingInfo pagingInfo, string knownVersion = null) + PagingInfo pagingInfo, string knownVersion = null, CancellationToken cancellationToken = default) { - using var session = await sessionProvider.OpenSession(); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); var documents = await session .Query() .Statistics(out var stats) .OrderByDescending(p => p.RaisedAt) .Paging(pagingInfo) - .ToListAsync(); + .ToListAsync(cancellationToken); var queryStats = stats.ToQueryStatsInfo(); diff --git a/src/ServiceControl.Persistence.RavenDB/MessageRedirects/MessageRedirectsDataStore.cs b/src/ServiceControl.Persistence.RavenDB/MessageRedirects/MessageRedirectsDataStore.cs index 6c162aed39..3e67fbb046 100644 --- a/src/ServiceControl.Persistence.RavenDB/MessageRedirects/MessageRedirectsDataStore.cs +++ b/src/ServiceControl.Persistence.RavenDB/MessageRedirects/MessageRedirectsDataStore.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using ServiceControl.Persistence.MessageRedirects; @@ -9,32 +10,32 @@ class MessageRedirectsDataStore(IRavenSessionProvider sessionProvider) : IMessag { public const string CollectionId = "messageredirects"; - public async Task> GetRedirects() + public async Task> GetRedirects(CancellationToken cancellationToken = default) { - using var session = await sessionProvider.OpenSession(); - var document = await session.LoadAsync(CollectionId); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); + var document = await session.LoadAsync(CollectionId, cancellationToken); return document == null ? [] : document.ToRedirects(); } - public Task AddRedirect(MessageRedirect redirect) => Mutate(document => document.Add(redirect)); + public Task AddRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => Mutate(document => document.Add(redirect), cancellationToken); - public Task UpdateRedirect(MessageRedirect redirect) => Mutate(document => document.Update(redirect)); + public Task UpdateRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => Mutate(document => document.Update(redirect), cancellationToken); - public Task RemoveRedirect(MessageRedirect redirect) => Mutate(document => document.Remove(redirect)); + public Task RemoveRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default) => Mutate(document => document.Remove(redirect), cancellationToken); - async Task Mutate(Action mutate) + async Task Mutate(Action mutate, CancellationToken cancellationToken) { - using var session = await sessionProvider.OpenSession(); - var document = await session.LoadAsync(CollectionId); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); + var document = await session.LoadAsync(CollectionId, cancellationToken); var changeVector = document == null ? null : session.Advanced.GetChangeVectorFor(document); document ??= new MessageRedirectsCollection(); mutate(document); - await session.StoreAsync(document, changeVector, CollectionId); - await session.SaveChangesAsync(); + await session.StoreAsync(document, changeVector, CollectionId, cancellationToken); + await session.SaveChangesAsync(cancellationToken); } } } diff --git a/src/ServiceControl.Persistence.RavenDB/RavenCustomCheckDataStore.cs b/src/ServiceControl.Persistence.RavenDB/RavenCustomCheckDataStore.cs index 06d385fafa..f4e6e643d7 100644 --- a/src/ServiceControl.Persistence.RavenDB/RavenCustomCheckDataStore.cs +++ b/src/ServiceControl.Persistence.RavenDB/RavenCustomCheckDataStore.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using Raven.Client.Documents; using Raven.Client.Documents.Commands; @@ -13,13 +14,13 @@ class RavenCustomCheckDataStore(IRavenSessionProvider sessionProvider) : ICustomChecksDataStore { - public async Task UpdateCustomCheckStatus(CustomCheckDetail detail) + public async Task UpdateCustomCheckStatus(CustomCheckDetail detail, CancellationToken cancellationToken = default) { var status = CheckStateChange.Unchanged; var id = MakeId(detail.GetDeterministicId()); - using var session = await sessionProvider.OpenSession(); - var customCheck = await session.LoadAsync(id); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); + var customCheck = await session.LoadAsync(id, cancellationToken); if (customCheck == null || (customCheck.Status == Status.Fail && !detail.HasFailed) || @@ -36,17 +37,17 @@ public async Task UpdateCustomCheckStatus(CustomCheckDetail de customCheck.ReportedAt = detail.ReportedAt; customCheck.FailureReason = detail.FailureReason; customCheck.OriginatingEndpoint = detail.OriginatingEndpoint; - await session.StoreAsync(customCheck); - await session.SaveChangesAsync(); + await session.StoreAsync(customCheck, cancellationToken); + await session.SaveChangesAsync(cancellationToken); return status; } static string MakeId(Guid id) => $"CustomChecks/{id}"; - public async Task>> GetStats(PagingInfo paging, string status = null) + public async Task>> GetStats(PagingInfo paging, string status = null, CancellationToken cancellationToken = default) { - using var session = await sessionProvider.OpenSession(); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); var query = session.Query().Statistics(out var stats); @@ -54,22 +55,22 @@ public async Task>> GetStats(PagingInfo paging, s var results = await query .Paging(paging) - .ToListAsync(); + .ToListAsync(cancellationToken); return new QueryResult>(results, new QueryStatsInfo($"{stats.ResultEtag}", stats.TotalResults, stats.IsStale)); } - public async Task DeleteCustomCheck(Guid id) + public async Task DeleteCustomCheck(Guid id, CancellationToken cancellationToken = default) { var documentId = MakeId(id); - using var session = await sessionProvider.OpenSession(new SessionOptions { NoTracking = true, NoCaching = true }); - await session.Advanced.RequestExecutor.ExecuteAsync(new DeleteDocumentCommand(documentId, null), session.Advanced.Context); + using var session = await sessionProvider.OpenSession(new SessionOptions { NoTracking = true, NoCaching = true }, cancellationToken); + await session.Advanced.RequestExecutor.ExecuteAsync(new DeleteDocumentCommand(documentId, null), session.Advanced.Context, token: cancellationToken); } - public async Task GetNumberOfFailedChecks() + public async Task GetNumberOfFailedChecks(CancellationToken cancellationToken = default) { - using var session = await sessionProvider.OpenSession(); - var failedCustomCheckCount = await session.Query().CountAsync(p => p.Status == Status.Fail); + using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken); + var failedCustomCheckCount = await session.Query().CountAsync(p => p.Status == Status.Fail, cancellationToken); return failedCustomCheckCount; } diff --git a/src/ServiceControl.Persistence/ICustomChecksDataStore.cs b/src/ServiceControl.Persistence/ICustomChecksDataStore.cs index 187cf472cf..4102c04506 100644 --- a/src/ServiceControl.Persistence/ICustomChecksDataStore.cs +++ b/src/ServiceControl.Persistence/ICustomChecksDataStore.cs @@ -2,16 +2,17 @@ namespace ServiceControl.Persistence { using System; using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using Infrastructure; using ServiceControl.Contracts.CustomChecks; public interface ICustomChecksDataStore { - Task UpdateCustomCheckStatus(CustomCheckDetail detail); + Task UpdateCustomCheckStatus(CustomCheckDetail detail, CancellationToken cancellationToken = default); - Task>> GetStats(PagingInfo paging, string status = null); - Task DeleteCustomCheck(Guid id); - Task GetNumberOfFailedChecks(); + Task>> GetStats(PagingInfo paging, string status = null, CancellationToken cancellationToken = default); + Task DeleteCustomCheck(Guid id, CancellationToken cancellationToken = default); + Task GetNumberOfFailedChecks(CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/ServiceControl.Persistence/IEventLogDataStore.cs b/src/ServiceControl.Persistence/IEventLogDataStore.cs index 09433bce1e..cfbad88a64 100644 --- a/src/ServiceControl.Persistence/IEventLogDataStore.cs +++ b/src/ServiceControl.Persistence/IEventLogDataStore.cs @@ -1,6 +1,7 @@ namespace ServiceControl.Persistence { using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using EventLog; using Infrastructure; @@ -20,7 +21,7 @@ public interface IEventLogDataStore /// on when the item is read back. /// /// The item to store. - Task Add(EventLogItem logItem); + Task Add(EventLogItem logItem, CancellationToken cancellationToken = default); /// /// Returns one page of event log items, newest RaisedAt first. @@ -40,6 +41,6 @@ public interface IEventLogDataStore /// one is added, since nothing else tells a client its cached page is now wrong. /// Task>> GetEventLogItems( - PagingInfo pagingInfo, string knownVersion = null); + PagingInfo pagingInfo, string knownVersion = null, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/ServiceControl.Persistence/MessageRedirects/IMessageRedirectsDataStore.cs b/src/ServiceControl.Persistence/MessageRedirects/IMessageRedirectsDataStore.cs index abac8013e9..e238e9e255 100644 --- a/src/ServiceControl.Persistence/MessageRedirects/IMessageRedirectsDataStore.cs +++ b/src/ServiceControl.Persistence/MessageRedirects/IMessageRedirectsDataStore.cs @@ -1,13 +1,14 @@ namespace ServiceControl.Persistence.MessageRedirects { using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; public interface IMessageRedirectsDataStore { - Task> GetRedirects(); - Task AddRedirect(MessageRedirect redirect); - Task UpdateRedirect(MessageRedirect redirect); - Task RemoveRedirect(MessageRedirect redirect); + Task> GetRedirects(CancellationToken cancellationToken = default); + Task AddRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default); + Task UpdateRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default); + Task RemoveRedirect(MessageRedirect redirect, CancellationToken cancellationToken = default); } } diff --git a/src/ServiceControl/CustomChecks/CustomCheckResultProcessor.cs b/src/ServiceControl/CustomChecks/CustomCheckResultProcessor.cs index 92679885cf..a4677006fb 100644 --- a/src/ServiceControl/CustomChecks/CustomCheckResultProcessor.cs +++ b/src/ServiceControl/CustomChecks/CustomCheckResultProcessor.cs @@ -21,10 +21,10 @@ public async Task ProcessResult(CustomCheckDetail checkDetail, CancellationToken { try { - var statusChange = await store.UpdateCustomCheckStatus(checkDetail); + var statusChange = await store.UpdateCustomCheckStatus(checkDetail, cancellationToken); await RaiseEvents(statusChange, checkDetail, cancellationToken); - var numberOfFailedChecks = await store.GetNumberOfFailedChecks(); + var numberOfFailedChecks = await store.GetNumberOfFailedChecks(cancellationToken); if (lastCount == numberOfFailedChecks) { diff --git a/src/ServiceControl/CustomChecks/DeleteCustomCheckHandler.cs b/src/ServiceControl/CustomChecks/DeleteCustomCheckHandler.cs index 342fb039ea..874e0962e3 100644 --- a/src/ServiceControl/CustomChecks/DeleteCustomCheckHandler.cs +++ b/src/ServiceControl/CustomChecks/DeleteCustomCheckHandler.cs @@ -10,7 +10,7 @@ class DeleteCustomCheckHandler(ICustomChecksDataStore customChecksDataStore, IDo { public async Task Handle(DeleteCustomCheck message, IMessageHandlerContext context) { - await customChecksDataStore.DeleteCustomCheck(message.Id); + await customChecksDataStore.DeleteCustomCheck(message.Id, context.CancellationToken); await domainEvents.Raise(new CustomCheckDeleted { Id = message.Id }, context.CancellationToken); } diff --git a/src/ServiceControl/CustomChecks/Web/CustomCheckController.cs b/src/ServiceControl/CustomChecks/Web/CustomCheckController.cs index ecdaca52d5..295b30ef90 100644 --- a/src/ServiceControl/CustomChecks/Web/CustomCheckController.cs +++ b/src/ServiceControl/CustomChecks/Web/CustomCheckController.cs @@ -23,7 +23,7 @@ public class CustomCheckController(ICustomChecksDataStore checksDataStore, IMess [HttpGet] public async Task> CustomChecks([FromQuery] PagingInfo pagingInfo, string status = null, CancellationToken cancellationToken = default) { - var stats = await checksDataStore.GetStats(pagingInfo, status); + var stats = await checksDataStore.GetStats(pagingInfo, status, cancellationToken); Response.WithPagingLinksAndTotalCount(pagingInfo, stats.QueryStats.TotalCount); Response.WithEtag(stats.QueryStats.ETag); diff --git a/src/ServiceControl/EventLog/AuditEventLogWriter.cs b/src/ServiceControl/EventLog/AuditEventLogWriter.cs index 3134d9dab5..d9b4baa9a9 100644 --- a/src/ServiceControl/EventLog/AuditEventLogWriter.cs +++ b/src/ServiceControl/EventLog/AuditEventLogWriter.cs @@ -26,7 +26,7 @@ public async Task Handle(IDomainEvent message, CancellationToken cancellationTok var logItem = mappings.ApplyMapping(message); - await dataStore.Add(logItem); + await dataStore.Add(logItem, cancellationToken); } readonly IEventLogDataStore dataStore; diff --git a/src/ServiceControl/EventLog/EventLogApiController.cs b/src/ServiceControl/EventLog/EventLogApiController.cs index 87fc1a31c0..824c5240bf 100644 --- a/src/ServiceControl/EventLog/EventLogApiController.cs +++ b/src/ServiceControl/EventLog/EventLogApiController.cs @@ -21,7 +21,7 @@ public class EventLogApiController(IEventLogDataStore logDataStore) : Controller public async Task>> Items([FromQuery] PagingInfo pagingInfo, CancellationToken cancellationToken = default) { // Passing knownVersion lets the persister skip work it would otherwise waste - var result = await logDataStore.GetEventLogItems(pagingInfo, Request.GetKnownVersion()); + var result = await logDataStore.GetEventLogItems(pagingInfo, Request.GetKnownVersion(), cancellationToken); Response.WithPagingLinksAndTotalCount(pagingInfo, result.QueryStats.TotalCount); Response.WithEtag(result.QueryStats.ETag); diff --git a/src/ServiceControl/MessageRedirects/Api/MessageRedirectsController.cs b/src/ServiceControl/MessageRedirects/Api/MessageRedirectsController.cs index c036e764a9..f3c8e61c0f 100644 --- a/src/ServiceControl/MessageRedirects/Api/MessageRedirectsController.cs +++ b/src/ServiceControl/MessageRedirects/Api/MessageRedirectsController.cs @@ -45,7 +45,7 @@ public async Task NewRedirects(MessageRedirectRequest request, Ca LastModified = DateTime.UtcNow }; - var redirects = await store.GetRedirects(); + var redirects = await store.GetRedirects(cancellationToken); var existing = redirects.FindById(messageRedirect.MessageRedirectId); @@ -72,7 +72,7 @@ public async Task NewRedirects(MessageRedirectRequest request, Ca return StatusCode((int)HttpStatusCode.Conflict, dependents); } - await store.AddRedirect(messageRedirect); + await store.AddRedirect(messageRedirect, cancellationToken); await events.Raise(new MessageRedirectCreated { @@ -105,7 +105,7 @@ public async Task UpdateRedirect(Guid messageRedirectId, MessageR return BadRequest(); } - var redirects = await store.GetRedirects(); + var redirects = await store.GetRedirects(cancellationToken); var messageRedirect = redirects.FindById(messageRedirectId); @@ -131,7 +131,7 @@ public async Task UpdateRedirect(Guid messageRedirectId, MessageR messageRedirect.LastModified = DateTime.UtcNow; - await store.UpdateRedirect(messageRedirect); + await store.UpdateRedirect(messageRedirect, cancellationToken); await events.Raise(messageRedirectChanged, cancellationToken); @@ -143,7 +143,7 @@ public async Task UpdateRedirect(Guid messageRedirectId, MessageR [HttpDelete] public async Task DeleteRedirect(Guid messageRedirectId, CancellationToken cancellationToken = default) { - var redirects = await store.GetRedirects(); + var redirects = await store.GetRedirects(cancellationToken); var messageRedirect = redirects.FindById(messageRedirectId); @@ -152,7 +152,7 @@ public async Task DeleteRedirect(Guid messageRedirectId, Cancella return NoContent(); } - await store.RemoveRedirect(messageRedirect); + await store.RemoveRedirect(messageRedirect, cancellationToken); await events.Raise(new MessageRedirectRemoved { @@ -169,7 +169,7 @@ await events.Raise(new MessageRedirectRemoved [HttpHead] public async Task CountRedirects(CancellationToken cancellationToken = default) { - var redirects = await store.GetRedirects(); + var redirects = await store.GetRedirects(cancellationToken); Response.WithDeterministicEtag(EtagHelper.CalculateEtag(redirects)); Response.WithTotalCount(redirects.Count); @@ -180,7 +180,7 @@ public async Task CountRedirects(CancellationToken cancellationToken = default) [HttpGet] public async Task> Redirects(string sort, string direction, [FromQuery] PagingInfo pagingInfo, CancellationToken cancellationToken = default) { - var redirects = await store.GetRedirects(); + var redirects = await store.GetRedirects(cancellationToken); var queryResult = redirects .Sort(sort, direction) diff --git a/src/ServiceControl/Recoverability/Editing/EditHandler.cs b/src/ServiceControl/Recoverability/Editing/EditHandler.cs index 82a90b1fd7..69104dce30 100644 --- a/src/ServiceControl/Recoverability/Editing/EditHandler.cs +++ b/src/ServiceControl/Recoverability/Editing/EditHandler.cs @@ -59,7 +59,7 @@ public async Task Handle(EditAndSend message, IMessageHandlerContext context) await session.SaveChanges(); } - var redirects = await redirectsStore.GetRedirects(); + var redirects = await redirectsStore.GetRedirects(context.CancellationToken); var attempt = failedMessage.ProcessingAttempts.Last(); diff --git a/src/ServiceControl/Recoverability/Retrying/RetryProcessor.cs b/src/ServiceControl/Recoverability/Retrying/RetryProcessor.cs index c61b08adcf..663d70c3be 100644 --- a/src/ServiceControl/Recoverability/Retrying/RetryProcessor.cs +++ b/src/ServiceControl/Recoverability/Retrying/RetryProcessor.cs @@ -59,7 +59,7 @@ async Task MoveStagedBatchesToForwardingBatch(CancellationToken cancellati if (stagingBatch != null) { logger.LogInformation("Staging batch {StagingBatchId}", stagingBatch.Id); - redirects = await redirectsStore.GetRedirects(); + redirects = await redirectsStore.GetRedirects(cancellationToken); var stagedMessages = await Stage(stagingBatch, cancellationToken); var skippedMessages = stagingBatch.InitialBatchSize - stagedMessages; await retryingManager.Skip(stagingBatch.RequestId, stagingBatch.RetryType, skippedMessages, cancellationToken);