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

Commit 6823b6e

Browse files
feat: Saves changes after adding MeshFile to db context
1 parent d8b5ade commit 6823b6e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/ServiceLayer.Mesh/Functions/DiscoveryFunction.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace ServiceLayer.Mesh.Functions
1212
public class DiscoveryFunction
1313
{
1414
private readonly ILogger _logger;
15-
1615
private readonly IMeshInboxService _meshInboxService;
1716
private readonly ServiceLayerDbContext _serviceLayerDbContext;
1817

@@ -28,7 +27,10 @@ public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer)
2827
{
2928
_logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
3029

31-
var response = await _meshInboxService.GetMessagesAsync(Environment.GetEnvironmentVariable("MailboxId"));
30+
var mailboxId = Environment.GetEnvironmentVariable("MailboxId")
31+
?? throw new InvalidOperationException($"Environment variable 'MailboxId' is not set or is empty.");
32+
33+
var response = await _meshInboxService.GetMessagesAsync(mailboxId);
3234

3335
if (response.Response.Messages.Count() > 500)
3436
{
@@ -47,15 +49,16 @@ public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer)
4749
{
4850
FileId = messageId,
4951
FileType = "",
50-
MailboxId = Environment.GetEnvironmentVariable("MailboxId"),
52+
MailboxId = mailboxId,
5153
Status = "Discovered"
5254
};
5355

54-
_serviceLayerDbContext.MeshFiles.Add(meshFile);
56+
await _serviceLayerDbContext.MeshFiles.AddAsync(meshFile);
57+
await _serviceLayerDbContext.SaveChangesAsync();
5558

5659
QueueClient queueClient;
5760

58-
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENV") == "Dev")
61+
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
5962
{
6063
queueClient = new QueueClient("UseDevelopmentStorage=true", "my-local-queue");
6164
}

0 commit comments

Comments
 (0)