From 5bb52a653a04182702955c1209606798a044709f Mon Sep 17 00:00:00 2001 From: Mikael Weaver Date: Thu, 24 Oct 2024 15:36:09 +0000 Subject: [PATCH] Add job notification ObjectDisposedException handling (#4682) * added object disposed handling for notifications * Fix build issue / unneded import * undo api changes * minimized change impact to export * simplified notification publishing * fix typos --- .../Operations/Export/ExportJobTask.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportJobTask.cs b/src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportJobTask.cs index 471a3bb738..fa4261b0ec 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportJobTask.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportJobTask.cs @@ -342,7 +342,31 @@ private async Task CompleteJobAsync(OperationStatus completionStatus, Cancellati dataSize, isAnonymizedExport); - await _mediator.Publish(new ExportTaskMetricsNotification(_exportJobRecord), CancellationToken.None); + try + { + await _mediator.Publish(new ExportTaskMetricsNotification(_exportJobRecord), cancellationToken); + } + catch (ObjectDisposedException ode) + { + if (cancellationToken.IsCancellationRequested) + { + _logger.LogWarning(ode, $"{nameof(ObjectDisposedException)}. Unable to publish {nameof(ExportTaskMetricsNotification)}. Cancellation was requested."); + } + else + { + _logger.LogCritical(ode, $"{nameof(ObjectDisposedException)}. Unable to publish {nameof(ExportTaskMetricsNotification)}."); + throw; + } + } + catch (OperationCanceledException oce) + { + _logger.LogWarning(oce, $"{nameof(OperationCanceledException)}. Unable to publish {nameof(ExportTaskMetricsNotification)}. Cancellation was requested."); + } + catch (Exception ex) + { + _logger.LogCritical(ex, $"Unable to publish {nameof(ExportTaskMetricsNotification)}."); + throw; + } } private async Task UpdateJobRecordAsync(CancellationToken cancellationToken)