fix: Replace IReadOnlySet/IReadOnlyDictionary with HashSet/Dictionary for performance (CA1859) and use LoggerMessage delegates (CA1848)
Source: CLAUDE.md observability section - Serilog structured logging and performance are first-class concerns Slice: ModelOperations/Scheduling, Domain/ModelFeedbackCycle Policy: CA1859 (concrete types over interfaces), CA1848 (LoggerMessage delegates) Changes: - ScheduledModelOperationJob: LoggerMessage.Define for warning/info logs - ModelOperationsDispatcherJob: LoggerMessage.Define for error logs - ModelOperationExecution: Dictionary<State, HashSet<State>> state machine - ModelFeedbackCycle: Dictionary<State, HashSet<State>> state machine Verification: - dotnet build: 0 errors, 0 warnings - dotnet test: 41/41 tests passed (ArchitectureTests 5, ModelOperations 17, SignalEngine 18) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,12 @@ public sealed class ModelOperationsDispatcherJob(
|
||||
ScheduleOccurrencePlanner occurrencePlanner,
|
||||
ILogger<ModelOperationsDispatcherJob> logger)
|
||||
{
|
||||
private static readonly Action<ILogger, string, string, Exception?> LogDispatchFailed =
|
||||
LoggerMessage.Define<string, string>(
|
||||
LogLevel.Error,
|
||||
new EventId(1, nameof(LogDispatchFailed)),
|
||||
"Failed to dispatch model operation {OperationCode} for {ScopeKey}.");
|
||||
|
||||
[Queue("q-control")]
|
||||
[DisableConcurrentExecution(timeoutInSeconds: 840)]
|
||||
[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||
@@ -47,7 +53,7 @@ public sealed class ModelOperationsDispatcherJob(
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to dispatch model operation {OperationCode} for {ScopeKey}.", item.OperationCode, item.ScopeKey);
|
||||
LogDispatchFailed(logger, item.OperationCode, item.ScopeKey, exception);
|
||||
await schedules.ReleaseAsync(
|
||||
item.ScheduleId,
|
||||
leaseOwner,
|
||||
|
||||
@@ -8,6 +8,18 @@ public sealed class ScheduledModelOperationJob(
|
||||
IModelOperationRequestService service,
|
||||
ILogger<ScheduledModelOperationJob> logger)
|
||||
{
|
||||
private static readonly Action<ILogger, string, string, Exception?> LogModelOperationNotCreated =
|
||||
LoggerMessage.Define<string, string>(
|
||||
LogLevel.Warning,
|
||||
new EventId(1, nameof(LogModelOperationNotCreated)),
|
||||
"Model operation {OperationCode} for {ScopeKey} was not created because the approved frozen context is unavailable or the idempotency key already exists.");
|
||||
|
||||
private static readonly Action<ILogger, string, string, string, string, Exception?> LogModelOperationRequested =
|
||||
LoggerMessage.Define<string, string, string, string>(
|
||||
LogLevel.Information,
|
||||
new EventId(2, nameof(LogModelOperationRequested)),
|
||||
"Requested model operation {OperationCode} for {ScopeKey} with model {ModelVersion} and dataset {DatasetId}. No model mutation is performed by this job.");
|
||||
|
||||
[AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Fail)]
|
||||
public async Task ExecuteAsync(
|
||||
Guid scheduleId,
|
||||
@@ -28,18 +40,16 @@ public sealed class ScheduledModelOperationJob(
|
||||
|
||||
if (request is null)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Model operation {OperationCode} for {ScopeKey} was not created because the approved frozen context is unavailable or the idempotency key already exists.",
|
||||
operationCode,
|
||||
scopeKey);
|
||||
LogModelOperationNotCreated(logger, operationCode, scopeKey, null);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogInformation(
|
||||
"Requested model operation {OperationCode} for {ScopeKey} with model {ModelVersion} and dataset {DatasetId}. No model mutation is performed by this job.",
|
||||
LogModelOperationRequested(
|
||||
logger,
|
||||
request.OperationCode,
|
||||
request.ScopeKey,
|
||||
request.Context.VersionSet.ModelVersion,
|
||||
request.Context.VersionSet.DatasetId);
|
||||
request.Context.VersionSet.DatasetId,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user