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

Commit d8b5ade

Browse files
committed
feat: adding push to queue
1 parent 44f4dbb commit d8b5ade

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

src/ServiceLayer.Mesh/Functions/DiscoveryFunction.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using Azure.Identity;
2+
using Azure.Storage.Queues;
13
using Microsoft.Azure.Functions.Worker;
24
using Microsoft.EntityFrameworkCore;
35
using Microsoft.Extensions.Logging;
46
using NHS.MESH.Client.Contracts.Services;
57
using ServiceLayer.Mesh.Data;
8+
using ServiceLayer.Mesh.Models;
69

710
namespace ServiceLayer.Mesh.Functions
811
{
@@ -33,16 +36,38 @@ public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer)
3336
// dotnet-mesh-client needs to be updated to support pagination for when inbox containers more than 500 messages
3437
}
3538

36-
foreach (var message in response.Response.Messages)
39+
foreach (var messageId in response.Response.Messages)
3740
{
3841
// Check if message has been seen before
39-
var doesFileIdExist = await _serviceLayerDbContext.MeshFiles.AnyAsync(m => m.FileId == message.ToString());
42+
var doesFileIdExist = await _serviceLayerDbContext.MeshFiles.AnyAsync(m => m.FileId == messageId.ToString());
4043

44+
if (!doesFileIdExist)
45+
{
46+
var meshFile = new MeshFile()
47+
{
48+
FileId = messageId,
49+
FileType = "",
50+
MailboxId = Environment.GetEnvironmentVariable("MailboxId"),
51+
Status = "Discovered"
52+
};
4153

42-
// If no then insert into db
43-
// Then enqueue message
54+
_serviceLayerDbContext.MeshFiles.Add(meshFile);
4455

45-
// If no then do nothing
56+
QueueClient queueClient;
57+
58+
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENV") == "Dev")
59+
{
60+
queueClient = new QueueClient("UseDevelopmentStorage=true", "my-local-queue");
61+
}
62+
else
63+
{
64+
var credential = new ManagedIdentityCredential();
65+
queueClient = new QueueClient(new Uri(Environment.GetEnvironmentVariable("QueueUrl")), credential);
66+
}
67+
68+
queueClient.CreateIfNotExists();
69+
queueClient.SendMessage(messageId);
70+
}
4671
}
4772

4873
if (myTimer.ScheduleStatus is not null)
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
2+
13
namespace ServiceLayer.Mesh.Models;
24

35
public class MeshFile
46
{
5-
public string FileId { get; set; }
7+
public required string FileId { get; set; }
8+
public required string FileType { get; set; }
9+
public required string MailboxId { get; set; }
10+
public required string Status { get; set; }
11+
public string? BlobPath { get; set; }
12+
public DateTime FirstSeenUtc { get; set; }
13+
public DateTime LastUpdatedUtc { get; set; }
614
}

src/ServiceLayer.Mesh/ServiceLayer.Mesh.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
</PropertyGroup>
99
<ItemGroup>
1010
<FrameworkReference Include="Microsoft.AspNetCore.App" />
11+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
12+
<PackageReference Include="Azure.Storage.Queues" Version="12.22.0" />
1113
<!-- Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4. -->
1214
<!-- <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> -->
1315
<!-- <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" /> -->

0 commit comments

Comments
 (0)