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 @@ -9,8 +9,3 @@ dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.IDE0040.severity = none

csharp_style_var_elsewhere = true:error

# Cancellation analyzer debt. These fire because Particular.Analyzers is no longer pinned to 0.9.0.
# They are scheduled work, not accepted exceptions: remove a line once this project has no
# violations of that rule left, and never add a rule back to this list.
dotnet_diagnostic.PS0003.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class InMemoryLicensingDataStore : ILicensingDataStore
List<string> reportMasks = [];
LicensedEndpointDetails? endpointDetails = null;

public Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints, CancellationToken cancellationToken)
public Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints, CancellationToken cancellationToken = default)
{
var filteredEndpoints = includePlatformEndpoints
? endpoints
Expand All @@ -27,7 +27,7 @@ public Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints
return Task.FromResult(filteredEndpoints);
}

public Task<Endpoint?> GetEndpoint(EndpointIdentifier id, CancellationToken cancellationToken)
public Task<Endpoint?> GetEndpoint(EndpointIdentifier id, CancellationToken cancellationToken = default)
{
if (endpoints.TryGetValue(id, out var endpoint))
{
Expand All @@ -39,7 +39,7 @@ public Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints
return Task.FromResult(endpoint);
}

public Task<IEnumerable<(EndpointIdentifier, Endpoint?)>> GetEndpoints(IList<EndpointIdentifier> endpointIds, CancellationToken cancellationToken)
public Task<IEnumerable<(EndpointIdentifier, Endpoint?)>> GetEndpoints(IList<EndpointIdentifier> endpointIds, CancellationToken cancellationToken = default)
{
var endpointLookup = endpointIds.Select(id => (id, endpoints.TryGetValue(id, out var endpoint) ? endpoint : null));

Expand All @@ -57,7 +57,7 @@ public Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints
return Task.FromResult(endpointLookup);
}

public Task SaveEndpoint(Endpoint endpoint, CancellationToken cancellationToken)
public Task SaveEndpoint(Endpoint endpoint, CancellationToken cancellationToken = default)
{
if (endpoints.TryGetValue(endpoint.Id, out var existingEndpoint))
{
Expand All @@ -68,7 +68,7 @@ public Task SaveEndpoint(Endpoint endpoint, CancellationToken cancellationToken)
return Task.CompletedTask;
}

public Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointThroughputByQueueName(IList<string> queueNames, CancellationToken cancellationToken)
public Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointThroughputByQueueName(IList<string> queueNames, CancellationToken cancellationToken = default)
{
var result = endpoints
.Where(endpoint => queueNames.Contains(endpoint.SanitizedName))
Expand All @@ -82,7 +82,7 @@ public Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointThrough
return Task.FromResult((IDictionary<string, IEnumerable<ThroughputData>>)result);
}

public async Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, IList<EndpointDailyThroughput> throughput, CancellationToken cancellationToken)
public async Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, IList<EndpointDailyThroughput> throughput, CancellationToken cancellationToken = default)
{
var id = new EndpointIdentifier(endpointName, throughputSource);
if (!endpoints.TryGetValue(id, out _))
Expand Down Expand Up @@ -111,7 +111,7 @@ public async Task RecordEndpointThroughput(string endpointName, ThroughputSource
await Task.CompletedTask;
}

public async Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken)
public async Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken = default)
{
userIndicatorUpdates.ForEach(e =>
{
Expand All @@ -130,12 +130,12 @@ public async Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userI
await Task.CompletedTask;
}

public async Task<bool> IsThereThroughputForLastXDays(int days, CancellationToken cancellationToken) => await Task.FromResult(
public async Task<bool> IsThereThroughputForLastXDays(int days, CancellationToken cancellationToken = default) => await Task.FromResult(
allThroughput.Any(endpointThroughput => endpointThroughput.Value.Any(
t => t.Key >= DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-days) &&
t.Key <= DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-1))));

public async Task<bool> IsThereThroughputForLastXDaysForSource(int days, ThroughputSource throughputSource, bool includeToday, CancellationToken cancellationToken)
public async Task<bool> IsThereThroughputForLastXDaysForSource(int days, ThroughputSource throughputSource, bool includeToday, CancellationToken cancellationToken = default)
{
var endDate = includeToday ? DateOnly.FromDateTime(DateTime.UtcNow) : DateOnly.FromDateTime(DateTime.UtcNow).AddDays(-1);

Expand All @@ -147,33 +147,33 @@ public async Task<bool> IsThereThroughputForLastXDaysForSource(int days, Through

List<Endpoint> GetAllConnectedEndpoints(string name) => endpoints.Where(w => w.SanitizedName == name || w.Id.Name == name).ToList();

public Task<BrokerMetadata> GetBrokerMetadata(CancellationToken cancellationToken) => Task.FromResult(brokerMetadata);
public Task<BrokerMetadata> GetBrokerMetadata(CancellationToken cancellationToken = default) => Task.FromResult(brokerMetadata);

public Task SaveBrokerMetadata(BrokerMetadata brokerMetadata, CancellationToken cancellationToken)
public Task SaveBrokerMetadata(BrokerMetadata brokerMetadata, CancellationToken cancellationToken = default)
{
this.brokerMetadata = brokerMetadata;
return Task.CompletedTask;
}

public Task<AuditServiceMetadata> GetAuditServiceMetadata(CancellationToken cancellationToken) => Task.FromResult(auditServiceMetadata);
public Task<AuditServiceMetadata> GetAuditServiceMetadata(CancellationToken cancellationToken = default) => Task.FromResult(auditServiceMetadata);

public Task SaveAuditServiceMetadata(AuditServiceMetadata auditServiceMetadata, CancellationToken cancellationToken)
public Task SaveAuditServiceMetadata(AuditServiceMetadata auditServiceMetadata, CancellationToken cancellationToken = default)
{
this.auditServiceMetadata = auditServiceMetadata;
return Task.CompletedTask;
}

public Task<List<string>> GetReportMasks(CancellationToken cancellationToken) => Task.FromResult(reportMasks);
public Task<List<string>> GetReportMasks(CancellationToken cancellationToken = default) => Task.FromResult(reportMasks);

public Task SaveReportMasks(List<string> reportMasks, CancellationToken cancellationToken)
public Task SaveReportMasks(List<string> reportMasks, CancellationToken cancellationToken = default)
{
this.reportMasks = reportMasks;
return Task.CompletedTask;
}

public Task<LicensedEndpointDetails?> GetLicensedEndpointDetails(CancellationToken cancellationToken) => Task.FromResult(endpointDetails);
public Task<LicensedEndpointDetails?> GetLicensedEndpointDetails(CancellationToken cancellationToken = default) => Task.FromResult(endpointDetails);

public Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, CancellationToken cancellationToken)
public Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, CancellationToken cancellationToken = default)
{
endpointDetails = result;
return Task.CompletedTask;
Expand Down
5 changes: 0 additions & 5 deletions src/Particular.LicensingComponent.Persistence/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none

# Cancellation analyzer debt. These fire because Particular.Analyzers is no longer pinned to 0.9.0.
# They are scheduled work, not accepted exceptions: remove a line once this project has no
# violations of that rule left, and never add a rule back to this list.
dotnet_diagnostic.PS0003.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@

public interface ILicensingDataStore
{
Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints, CancellationToken cancellationToken);
Task<IEnumerable<Endpoint>> GetAllEndpoints(bool includePlatformEndpoints, CancellationToken cancellationToken = default);

Task<Endpoint?> GetEndpoint(string endpointName, ThroughputSource throughputSource, CancellationToken cancellationToken) =>
Task<Endpoint?> GetEndpoint(string endpointName, ThroughputSource throughputSource, CancellationToken cancellationToken = default) =>
GetEndpoint(new EndpointIdentifier(endpointName, throughputSource), cancellationToken);

Task<Endpoint?> GetEndpoint(EndpointIdentifier id, CancellationToken cancellationToken = default);

Task<IEnumerable<(EndpointIdentifier Id, Endpoint? Endpoint)>> GetEndpoints(IList<EndpointIdentifier> endpointIds, CancellationToken cancellationToken);
Task<IEnumerable<(EndpointIdentifier Id, Endpoint? Endpoint)>> GetEndpoints(IList<EndpointIdentifier> endpointIds, CancellationToken cancellationToken = default);

Task SaveEndpoint(Endpoint endpoint, CancellationToken cancellationToken);
Task SaveEndpoint(Endpoint endpoint, CancellationToken cancellationToken = default);

Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointThroughputByQueueName(IList<string> queueNames, CancellationToken cancellationToken);
Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointThroughputByQueueName(IList<string> queueNames, CancellationToken cancellationToken = default);

Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, DateOnly date, long messageCount, CancellationToken cancellationToken) =>
Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, DateOnly date, long messageCount, CancellationToken cancellationToken = default) =>
RecordEndpointThroughput(endpointName, throughputSource, [new EndpointDailyThroughput(date, messageCount)], cancellationToken);

Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, IList<EndpointDailyThroughput> throughput, CancellationToken cancellationToken);
Task RecordEndpointThroughput(string endpointName, ThroughputSource throughputSource, IList<EndpointDailyThroughput> throughput, CancellationToken cancellationToken = default);

Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken);
Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken = default);

Task<bool> IsThereThroughputForLastXDays(int days, CancellationToken cancellationToken);
Task<bool> IsThereThroughputForLastXDaysForSource(int days, ThroughputSource throughputSource, bool includeToday, CancellationToken cancellationToken);
Task<bool> IsThereThroughputForLastXDays(int days, CancellationToken cancellationToken = default);
Task<bool> IsThereThroughputForLastXDaysForSource(int days, ThroughputSource throughputSource, bool includeToday, CancellationToken cancellationToken = default);

Task<BrokerMetadata> GetBrokerMetadata(CancellationToken cancellationToken);
Task<BrokerMetadata> GetBrokerMetadata(CancellationToken cancellationToken = default);

Task SaveBrokerMetadata(BrokerMetadata brokerMetadata, CancellationToken cancellationToken);
Task SaveBrokerMetadata(BrokerMetadata brokerMetadata, CancellationToken cancellationToken = default);

Task<AuditServiceMetadata> GetAuditServiceMetadata(CancellationToken cancellationToken = default);

Task SaveAuditServiceMetadata(AuditServiceMetadata auditServiceMetadata, CancellationToken cancellationToken);
Task<List<string>> GetReportMasks(CancellationToken cancellationToken);
Task SaveReportMasks(List<string> reportMasks, CancellationToken cancellationToken);
Task SaveAuditServiceMetadata(AuditServiceMetadata auditServiceMetadata, CancellationToken cancellationToken = default);
Task<List<string>> GetReportMasks(CancellationToken cancellationToken = default);
Task SaveReportMasks(List<string> reportMasks, CancellationToken cancellationToken = default);

Task<LicensedEndpointDetails?> GetLicensedEndpointDetails(CancellationToken cancellationToken);
Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, CancellationToken cancellationToken);
Task<LicensedEndpointDetails?> GetLicensedEndpointDetails(CancellationToken cancellationToken = default);
Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, CancellationToken cancellationToken = default);
}
10 changes: 0 additions & 10 deletions src/ServiceControl.Persistence.EFCore/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none

# Cancellation analyzer debt. These fire because Particular.Analyzers is no longer pinned to 0.9.0.
# They are scheduled work, not accepted exceptions: remove a line once this project has no
# violations of that rule left, and never add a rule back to this list.
dotnet_diagnostic.PS0003.severity = none
dotnet_diagnostic.PS0004.severity = none
dotnet_diagnostic.PS0013.severity = none
dotnet_diagnostic.PS0017.severity = none
dotnet_diagnostic.PS0018.severity = none
dotnet_diagnostic.PS0019.severity = none

# Disable style rules for auto-generated EF migrations
[Migrations/**.cs]
dotnet_diagnostic.IDE0065.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BodyStorage(IServiceScopeFactory scopeFactory, IBodyStoragePersiste
{
public async Task<MessageBodyStreamResult?> TryFetch(string bodyId, CancellationToken cancellationToken = default)
{
var row = await ExecuteWithDbContext(dbContext => ResolveBody(dbContext, bodyId, cancellationToken));
var row = await ExecuteWithDbContext((dbContext, token) => ResolveBody(dbContext, bodyId, token), cancellationToken);

if (row == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ServiceControl.Persistence.EFCore.Implementation;

public class CustomCheckDataStore(IServiceScopeFactory scopeFactory) : DataStoreBase(scopeFactory), ICustomChecksDataStore
{
public Task<CheckStateChange> UpdateCustomCheckStatus(CustomCheckDetail detail, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context =>
public Task<CheckStateChange> UpdateCustomCheckStatus(CustomCheckDetail detail, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async (context, token) =>
{
var status = CheckStateChange.Unchanged;

Expand Down Expand Up @@ -44,11 +44,11 @@ await context.UpsertAsync([detail.GetDeterministicId()],
entity.ReportedAt = detail.ReportedAt;
entity.FailureReason = detail.FailureReason;
},
cancellationToken);
token);
return status;
});
}, cancellationToken);

public Task<QueryResult<IList<CustomCheck>>> GetStats(PagingInfo paging, string? status = null, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context =>
public Task<QueryResult<IList<CustomCheck>>> GetStats(PagingInfo paging, string? status = null, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async (context, token) =>
{
var query = context.CustomChecks.AsQueryable().AsNoTracking();

Expand All @@ -63,7 +63,7 @@ public Task<QueryResult<IList<CustomCheck>>> GetStats(PagingInfo paging, string?
.OrderBy(c => c.ReportedAt)
.Skip(paging.Offset)
.Take(paging.PageSize)
.ToListAsync(cancellationToken);
.ToListAsync(token);

return new QueryResult<IList<CustomCheck>>(page.Select(c => new CustomCheck
{
Expand All @@ -74,9 +74,9 @@ public Task<QueryResult<IList<CustomCheck>>> GetStats(PagingInfo paging, string?
ReportedAt = c.ReportedAt,
FailureReason = c.FailureReason
}).ToList(), new QueryStatsInfo("", page.Count, false));
});
}, cancellationToken);

public Task DeleteCustomCheck(Guid id, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().Where(cc => cc.Id == id).ExecuteDeleteAsync(cancellationToken));
public Task DeleteCustomCheck(Guid id, CancellationToken cancellationToken = default) => ExecuteWithDbContext(async (context, token) => await context.CustomChecks.AsNoTracking().Where(cc => cc.Id == id).ExecuteDeleteAsync(token), cancellationToken);

public Task<int> GetNumberOfFailedChecks(CancellationToken cancellationToken = default) => ExecuteWithDbContext(async context => await context.CustomChecks.AsNoTracking().CountAsync(p => p.Status == Status.Fail, cancellationToken));
public Task<int> GetNumberOfFailedChecks(CancellationToken cancellationToken = default) => ExecuteWithDbContext(async (context, token) => await context.CustomChecks.AsNoTracking().CountAsync(p => p.Status == Status.Fail, token), cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public abstract class DataStoreBase(IServiceScopeFactory scopeFactory)
/// <summary>
/// Executes an operation with a scoped DbContext, returning a result
/// </summary>
protected async Task<T> ExecuteWithDbContext<T>(Func<ServiceControlDbContext, Task<T>> operation)
protected async Task<T> ExecuteWithDbContext<T>(Func<ServiceControlDbContext, CancellationToken, Task<T>> operation, CancellationToken cancellationToken = default)
{
await using var scope = scopeFactory.CreateAsyncScope();// Use CreateAsyncScope for async disposal
var dbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContext>();
return await operation(dbContext);
return await operation(dbContext, cancellationToken);
}

/// <summary>
/// Executes an operation with a scoped DbContext, without returning a result
/// </summary>
protected async Task ExecuteWithDbContext(Func<ServiceControlDbContext, Task> operation)
protected async Task ExecuteWithDbContext(Func<ServiceControlDbContext, CancellationToken, Task> operation, CancellationToken cancellationToken = default)
{
await using var scope = scopeFactory.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContext>();
await operation(dbContext);
await operation(dbContext, cancellationToken);
}

/// <summary>
Expand Down
Loading
Loading