11using Azure . Storage . Blobs ;
22using Azure . Storage . Blobs . Models ;
3- using Azure . Storage . Queues ;
43using Microsoft . Azure . Functions . Worker ;
54using Microsoft . EntityFrameworkCore ;
65using Microsoft . Extensions . Logging ;
1110
1211namespace ServiceLayer . Mesh . Functions ;
1312
14- public class ExtractFunction
13+ public class FileExtractFunction (
14+ ILogger logger ,
15+ IMeshInboxService meshInboxService ,
16+ ServiceLayerDbContext serviceLayerDbContext ,
17+ IFileTransformQueueClient fileTransformQueueClient ,
18+ BlobContainerClient blobContainerClient )
1519{
16- private readonly ILogger _logger ;
17- private readonly IMeshInboxService _meshInboxService ;
18- private readonly ServiceLayerDbContext _serviceLayerDbContext ;
19- private readonly QueueClient _queueClient ;
20- private readonly BlobContainerClient _blobContainerClient ;
21-
22- public ExtractFunction ( ILogger logger , IMeshInboxService meshInboxService , ServiceLayerDbContext serviceLayerDbContext , QueueClient queueClient , BlobContainerClient blobClient )
23- {
24- _logger = logger ;
25- _meshInboxService = meshInboxService ;
26- _serviceLayerDbContext = serviceLayerDbContext ;
27- _queueClient = queueClient ;
28- _blobContainerClient = blobClient ;
29- }
30-
31- [ Function ( "ExtractFunction" ) ]
20+ [ Function ( "FileExtractFunction" ) ]
3221 public async Task Run ( [ QueueTrigger ( "file-extract" ) ] FileExtractQueueMessage message ) // TODO: Queue name
3322 {
34- _logger . LogInformation ( $ "ExtractFunction started at: { DateTime . Now } ") ;
23+ logger . LogInformation ( $ "ExtractFunction started at: { DateTime . Now } ") ;
3524
36- await using var transaction = await _serviceLayerDbContext . Database . BeginTransactionAsync ( ) ;
25+ await using var transaction = await serviceLayerDbContext . Database . BeginTransactionAsync ( ) ;
3726
38- var file = await _serviceLayerDbContext . MeshFiles
27+ var file = await serviceLayerDbContext . MeshFiles
3928 . FirstOrDefaultAsync ( f => f . FileId == message . FileId ) ;
4029
4130 if ( file == null )
4231 {
4332 // TODO - do we want to throw exception or just exit silently?
33+ // ANswer - exit silenty
4434 throw new InvalidOperationException ( "File not found" ) ;
4535 }
4636
@@ -51,19 +41,20 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
5141 file . Status == MeshFileStatus . Extracting && file . LastUpdatedUtc > DateTime . UtcNow . AddHours ( - 12 ) )
5242 {
5343 // TODO - do we want to throw exception or just exit silently?
44+ // ANswer - exit silenty
5445 throw new InvalidOperationException ( "File is not in expected status" ) ;
5546 }
5647
5748 file . Status = MeshFileStatus . Extracting ;
5849 file . LastUpdatedUtc = DateTime . UtcNow ;
5950
60- await _serviceLayerDbContext . SaveChangesAsync ( ) ;
51+ await serviceLayerDbContext . SaveChangesAsync ( ) ;
6152 await transaction . CommitAsync ( ) ;
6253
6354 var mailboxId = Environment . GetEnvironmentVariable ( "MeshMailboxId" )
6455 ?? throw new InvalidOperationException ( $ "Environment variable 'MeshMailboxId' is not set or is empty.") ;
6556
66- var meshResponse = await _meshInboxService . GetMessageByIdAsync ( mailboxId , file . FileId ) ;
57+ var meshResponse = await meshInboxService . GetMessageByIdAsync ( mailboxId , file . FileId ) ;
6758 if ( ! meshResponse . IsSuccessful )
6859 {
6960 // TODO - what to do if unsuccessful?
@@ -75,17 +66,17 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
7566
7667 public async Task < bool > UploadFileToBlobStorage ( BlobFile blobFile , bool overwrite = false )
7768 {
78- var blobClient = _blobContainerClient . GetBlobClient ( blobFile . FileName ) ;
69+ var blobClient = blobContainerClient . GetBlobClient ( blobFile . FileName ) ;
7970
80- await _blobContainerClient . CreateIfNotExistsAsync ( PublicAccessType . None ) ;
71+ await blobContainerClient . CreateIfNotExistsAsync ( PublicAccessType . None ) ;
8172
8273 try
8374 {
8475 await blobClient . UploadAsync ( blobFile . Data , overwrite : overwrite ) ;
8576 }
8677 catch ( Exception ex )
8778 {
88- _logger . LogError ( ex , "There has been a problem while uploading the file: {Message}" , ex . Message ) ;
79+ logger . LogError ( ex , "There has been a problem while uploading the file: {Message}" , ex . Message ) ;
8980 return false ;
9081 }
9182
0 commit comments