feat(notification-outbox): operator Retry/Discard emit audit rows with operator identity
Additive RequestedBy on Retry/DiscardNotificationRequest, plumbed from the Central UI. RetryAsync emits a NotifyDeliver Submitted row (records who un-parked); Discard stamps the operator on the Terminal row. Best-effort — audit failure never aborts the action.
This commit is contained in:
@@ -587,12 +587,14 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
private async Task EmitTerminalAuditAsync(
|
||||
Notification notification,
|
||||
DateTimeOffset now,
|
||||
string? errorMessage)
|
||||
string? errorMessage,
|
||||
string? actorOverride = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var terminalStatus = MapNotificationStatusToAuditStatus(notification.Status);
|
||||
var evt = BuildNotifyDeliverEvent(notification, now, terminalStatus, errorMessage);
|
||||
var evt = BuildNotifyDeliverEvent(
|
||||
notification, now, terminalStatus, errorMessage, actorOverride: actorOverride);
|
||||
await _auditWriter.WriteAsync(evt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -677,7 +679,8 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
DateTimeOffset now,
|
||||
AuditStatus status,
|
||||
string? errorMessage,
|
||||
int? durationMs = null)
|
||||
int? durationMs = null,
|
||||
string? actorOverride = null)
|
||||
{
|
||||
Guid? correlationId = Guid.TryParse(notification.NotificationId, out var parsed)
|
||||
? parsed
|
||||
@@ -688,11 +691,12 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
kind: AuditKind.NotifyDeliver,
|
||||
status: status,
|
||||
occurredAtUtc: now.UtcDateTime,
|
||||
// Central dispatch — a system identity per the Actor-column spec;
|
||||
// there is no per-call authenticated user here. The originating
|
||||
// script is still captured on SourceScript (and on the upstream
|
||||
// NotifySend row).
|
||||
actor: SystemActor,
|
||||
// Central dispatch is a system identity per the Actor-column spec —
|
||||
// there is no per-call authenticated user for automatic delivery. An
|
||||
// operator-initiated transition (Retry/Discard) passes actorOverride
|
||||
// so the row is attributable to the person who un-parked/cancelled it
|
||||
// (Task 13). The originating script is still captured on SourceScript.
|
||||
actor: actorOverride ?? SystemActor,
|
||||
target: notification.ListName,
|
||||
correlationId: correlationId,
|
||||
// ExecutionId: the originating script execution's id,
|
||||
@@ -973,9 +977,41 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
notification.LastError = null;
|
||||
await repository.UpdateAsync(notification);
|
||||
|
||||
// Operator re-queued a parked notification. Emit a Submitted NotifyDeliver
|
||||
// row attributing the un-park to the operator — otherwise the lifecycle
|
||||
// reads Parked → Attempted → Delivered with no record of who un-parked it
|
||||
// (Task 13). Best-effort: audit failure never aborts the retry.
|
||||
await EmitRetrySubmittedAuditAsync(notification, DateTimeOffset.UtcNow, request.RequestedBy);
|
||||
|
||||
return new RetryNotificationResponse(request.CorrelationId, Success: true, ErrorMessage: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emits a single <see cref="AuditKind.NotifyDeliver"/> row with
|
||||
/// <see cref="AuditStatus.Submitted"/> recording that <paramref name="actorOverride"/>
|
||||
/// re-queued a parked notification. Best-effort with the same
|
||||
/// audit-never-affects-the-action shape as <see cref="EmitTerminalAuditAsync"/>.
|
||||
/// </summary>
|
||||
private async Task EmitRetrySubmittedAuditAsync(
|
||||
Notification notification,
|
||||
DateTimeOffset now,
|
||||
string? actorOverride)
|
||||
{
|
||||
try
|
||||
{
|
||||
var evt = BuildNotifyDeliverEvent(
|
||||
notification, now, AuditStatus.Submitted, errorMessage: null, actorOverride: actorOverride);
|
||||
await _auditWriter.WriteAsync(evt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
ex,
|
||||
"Failed to emit Submitted (operator retry) audit row for notification {NotificationId}.",
|
||||
notification.NotificationId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a manual discard request. Only a <c>Parked</c> notification can be discarded;
|
||||
/// it is moved to the terminal <c>Discarded</c> status.
|
||||
@@ -1018,7 +1054,10 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
// Emit a Discarded NotifyDeliver row to match the dispatcher's
|
||||
// Delivered/Parked emissions; the row carries no error message because
|
||||
// the discard is an operator-driven cancellation, not a delivery error.
|
||||
await EmitTerminalAuditAsync(notification, DateTimeOffset.UtcNow, errorMessage: null);
|
||||
// The operator identity is stamped as Actor so the cancellation is
|
||||
// attributable (Task 13).
|
||||
await EmitTerminalAuditAsync(
|
||||
notification, DateTimeOffset.UtcNow, errorMessage: null, actorOverride: request.RequestedBy);
|
||||
|
||||
return new DiscardNotificationResponse(request.CorrelationId, Success: true, ErrorMessage: null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user