Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 6e70a42

Browse files
feat: Updated FileExtractFunction to log warning and continue when acknowledgement fails
1 parent cdfea60 commit 6e70a42

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/ServiceLayer.Mesh/Functions/FileExtractFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private async Task ProcessFileExtraction(MeshFile file, FileExtractQueueMessage
104104
var meshAcknowledgementResponse = await meshInboxService.AcknowledgeMessageByIdAsync(configuration.NbssMeshMailboxId, message.FileId);
105105
if (!meshAcknowledgementResponse.IsSuccessful)
106106
{
107-
throw new InvalidOperationException($"Mesh acknowledgement failed: {meshAcknowledgementResponse.Error}");
107+
logger.LogWarning("Mesh acknowledgement failed: {error}.\nThis is not a fatal error so processing will continue.", meshAcknowledgementResponse.Error);
108108
}
109109

110110
file.BlobPath = blobPath;

tests/ServiceLayer.Mesh.Tests/Functions/FileExtractFunctionTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public async Task Run_GetMessageFails_ErrorLoggedAndFileSentToPoisonQueue()
276276
}
277277

278278
[Fact]
279-
public async Task Run_AcknowledgeMessageFails_ErrorLoggedAndFileSentToPoisonQueue()
279+
public async Task Run_AcknowledgeMessageFails_WarningLoggedAndProcessingContinuesAsNormal()
280280
{
281281
// Arrange
282282
var fileId = "file-4";
@@ -293,6 +293,7 @@ public async Task Run_AcknowledgeMessageFails_ErrorLoggedAndFileSentToPoisonQueu
293293
await _dbContext.SaveChangesAsync();
294294

295295
var content = new byte[] { 1, 2, 3 };
296+
const string blobPath = "directory/fileName";
296297

297298
_meshInboxServiceMock.Setup(s => s.GetMessageByIdAsync(file.MailboxId, fileId))
298299
.ReturnsAsync(new MeshResponse<GetMessageResponse>
@@ -318,19 +319,21 @@ public async Task Run_AcknowledgeMessageFails_ErrorLoggedAndFileSentToPoisonQueu
318319
// Assert
319320
_loggerMock.Verify(
320321
x => x.Log(
321-
LogLevel.Error,
322+
LogLevel.Warning,
322323
It.IsAny<EventId>(),
323-
It.Is<It.IsAnyType>((v, t) => v.ToString() == $"An exception occurred during file extraction for fileId: {fileId}"),
324-
It.Is<InvalidOperationException>(e => e.Message.StartsWith("Mesh acknowledgement failed: ")),
324+
It.Is<It.IsAnyType>((v, t) =>
325+
v.ToString().StartsWith("Mesh acknowledgement failed: ") &&
326+
v.ToString().EndsWith("This is not a fatal error so processing will continue.")),
327+
null,
325328
It.IsAny<Func<It.IsAnyType, Exception?, string>>()
326329
), Times.Once);
327330
_blobStoreMock.Verify(b => b.UploadAsync(file, content), Times.Once);
328331
_meshInboxServiceMock.Verify(m => m.AcknowledgeMessageByIdAsync(file.MailboxId, file.FileId), Times.Once);
329-
_fileTransformQueueClientMock.Verify(q => q.EnqueueFileTransformAsync(It.IsAny<MeshFile>()), Times.Never);
330-
_fileExtractQueueClientMock.Verify(q => q.SendToPoisonQueueAsync(message), Times.Once);
332+
_fileTransformQueueClientMock.Verify(q => q.EnqueueFileTransformAsync(file), Times.Once);
333+
_fileExtractQueueClientMock.Verify(q => q.SendToPoisonQueueAsync(message), Times.Never);
331334
var updatedFile = _dbContext.MeshFiles.First();
332-
Assert.Null(updatedFile.BlobPath);
333-
Assert.Equal(MeshFileStatus.FailedExtract, updatedFile.Status);
335+
Assert.Equal(blobPath, updatedFile.BlobPath);
336+
Assert.Equal(MeshFileStatus.Extracted, updatedFile.Status);
334337
Assert.True(updatedFile.LastUpdatedUtc > originalLastUpdatedUtc);
335338
}
336339
}

0 commit comments

Comments
 (0)