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

Commit 7e9de12

Browse files
feat: Improved logging in FileExtractFunction
1 parent 239523e commit 7e9de12

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/ServiceLayer.Mesh/Functions/FileDiscoveryFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class FileDiscoveryFunction(
1919
[Function("FileDiscoveryFunction")]
2020
public async Task Run([TimerTrigger("%FileDiscoveryTimerExpression%")] TimerInfo myTimer)
2121
{
22-
logger.LogInformation($"DiscoveryFunction started at: {DateTime.Now}");
22+
logger.LogInformation("{functionName} started at: {time}", nameof(FileDiscoveryFunction), DateTime.UtcNow);
2323

2424
var response = await meshInboxService.GetMessagesAsync(configuration.NbssMeshMailboxId);
2525

src/ServiceLayer.Mesh/Functions/FileExtractFunction.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class FileExtractFunction(
2020
IMeshFilesBlobStore meshFileBlobStore)
2121
{
2222
[Function("FileExtractFunction")]
23-
public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage message) // TODO: Queue name
23+
public async Task Run([QueueTrigger("%FileExtractQueueName%")] FileExtractQueueMessage message)
2424
{
25-
logger.LogInformation($"ExtractFunction started at: {DateTime.Now}");
25+
logger.LogInformation("{functionName} started at: {time}", nameof(FileDiscoveryFunction), DateTime.UtcNow);
2626

2727
await using var transaction = await serviceLayerDbContext.Database.BeginTransactionAsync();
2828

@@ -31,20 +31,22 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
3131

3232
if (file == null)
3333
{
34-
// TODO - do we want to throw exception or just exit silently?
35-
// ANswer - exit silenty
36-
throw new InvalidOperationException("File not found");
34+
logger.LogWarning("File with id: {fileId} not found in MeshFiles table. Exiting function.", message.FileId);
35+
return;
3736
}
3837

3938
// We only want to extract files if they are in a Discovered state,
40-
// or are in an Extracting state and have been last touched over 12 hours ago.
39+
// or are in an Extracting state and were last touched over 12 hours ago.
4140
var expectedStatuses = new[] { MeshFileStatus.Discovered, MeshFileStatus.Extracting };
4241
if (!expectedStatuses.Contains(file.Status) ||
43-
file.Status == MeshFileStatus.Extracting && file.LastUpdatedUtc > DateTime.UtcNow.AddHours(-12))
42+
(file.Status == MeshFileStatus.Extracting && file.LastUpdatedUtc > DateTime.UtcNow.AddHours(-12)))
4443
{
45-
// TODO - do we want to throw exception or just exit silently?
46-
// ANswer - exit silenty
47-
throw new InvalidOperationException("File is not in expected status");
44+
logger.LogWarning(
45+
"File with id: {fileId} found in MeshFiles table but has unexpected Status: {status}, LastUpdatedUtc: {lastUpdatedUtc}. Exiting function.",
46+
message.FileId,
47+
file.Status,
48+
file.LastUpdatedUtc);
49+
return;
4850
}
4951

5052
file.Status = MeshFileStatus.Extracting;
@@ -58,7 +60,6 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
5860
var meshResponse = await meshInboxService.GetMessageByIdAsync(configuration.NbssMeshMailboxId, file.FileId);
5961
if (!meshResponse.IsSuccessful)
6062
{
61-
// TODO - what to do if unsuccessful?
6263
throw new InvalidOperationException($"Mesh extraction failed: {meshResponse.Error}");
6364
}
6465

@@ -67,20 +68,19 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
6768
var meshAcknowledgementResponse = await meshInboxService.AcknowledgeMessageByIdAsync(configuration.NbssMeshMailboxId, message.FileId);
6869
if (!meshAcknowledgementResponse.IsSuccessful)
6970
{
70-
// TODO - what to do if unsuccessful?
71-
throw new InvalidOperationException($"Mesh acknowledgement failed: {meshResponse.Error}");
71+
throw new InvalidOperationException($"Mesh acknowledgement failed: {meshAcknowledgementResponse.Error}");
7272
}
7373

74+
file.BlobPath = blobPath;
7475
file.Status = MeshFileStatus.Extracted;
7576
file.LastUpdatedUtc = DateTime.UtcNow;
76-
file.BlobPath = blobPath;
7777
await serviceLayerDbContext.SaveChangesAsync();
7878

7979
await fileTransformQueueClient.EnqueueFileTransformAsync(file);
8080
}
8181
catch (Exception ex)
8282
{
83-
logger.LogError(ex, "");
83+
logger.LogError(ex, "An exception occurred during file extraction for fileId: {fileId}", message.FileId);
8484
file.Status = MeshFileStatus.FailedExtract;
8585
file.LastUpdatedUtc = DateTime.UtcNow;
8686
await serviceLayerDbContext.SaveChangesAsync();

0 commit comments

Comments
 (0)