|
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; |
2 | 8 |
|
3 | | -public class FileRetryFunction |
| 9 | +namespace ServiceLayer.Mesh.Functions |
4 | 10 | { |
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 | + } |
6 | 47 | } |
0 commit comments