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

Commit 29ea6ff

Browse files
committed
feat: adding Retry function
Signed-off-by: Tyrrellion <[email protected]>
1 parent 4f64ffd commit 29ea6ff

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed
Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
1-
namespace ServiceLayer.Mesh.Functions;
1+
using Microsoft.Azure.Functions.Worker;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.Extensions.Logging;
4+
using NHS.MESH.Client.Contracts.Services;
5+
using ServiceLayer.Mesh.Data;
6+
using ServiceLayer.Mesh.Messaging;
7+
using ServiceLayer.Mesh.Models;
28

3-
public class FileRetryFunction
9+
namespace ServiceLayer.Mesh.Functions
410
{
5-
11+
public class FileRetryFunction(
12+
ILogger<FileRetryFunction> logger,
13+
IMeshInboxService meshInboxService,
14+
ServiceLayerDbContext serviceLayerDbContext,
15+
IFileExtractQueueClient fileExtractQueueClient)
16+
{
17+
[Function("FileRetryFunction")]
18+
public async Task Run([TimerTrigger("%FileRetryTimerExpression%")] TimerInfo myTimer)
19+
{
20+
var twelveHoursAgo = DateTime.UtcNow.AddHours(-12);
21+
22+
var files = await serviceLayerDbContext.MeshFiles
23+
.Where(f =>
24+
(f.Status == MeshFileStatus.Discovered ||
25+
f.Status == MeshFileStatus.Extracting ||
26+
f.Status == MeshFileStatus.Extracted ||
27+
f.Status == MeshFileStatus.Transforming) && f.LastUpdatedUtc <= twelveHoursAgo)
28+
.ToListAsync();
29+
30+
foreach (var file in files)
31+
{
32+
if (file.Status == MeshFileStatus.Discovered || file.Status == MeshFileStatus.Extracting)
33+
{
34+
await fileExtractQueueClient.EnqueueFileExtractAsync(file);
35+
file.LastUpdatedUtc = DateTime.UtcNow;
36+
await serviceLayerDbContext.SaveChangesAsync();
37+
}
38+
else if (file.Status == MeshFileStatus.Extracted || file.Status == MeshFileStatus.Transforming)
39+
{
40+
//await fileExtractQueueClient.EnqueueFileExtractAsync(file);
41+
file.LastUpdatedUtc = DateTime.UtcNow;
42+
await serviceLayerDbContext.SaveChangesAsync();
43+
}
44+
}
45+
}
46+
}
647
}

0 commit comments

Comments
 (0)