From 908db33433302fa4413902bf493e9f43cc2e3047 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Mon, 1 Jul 2024 17:39:49 -0400 Subject: [PATCH] outbox Dir --- .../Configuration/MessageOutboxOptions.cs | 2 +- .../Services/MessageOutboxDeliveryService.cs | 8 +++++++- .../Services/MessageOutboxService.cs | 2 +- src/SIL.Machine.Serval.EngineServer/appsettings.json | 3 ++- src/SIL.Machine.Serval.JobServer/appsettings.json | 4 ++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/SIL.Machine.AspNetCore/Configuration/MessageOutboxOptions.cs b/src/SIL.Machine.AspNetCore/Configuration/MessageOutboxOptions.cs index 92bc74eac..e4b9946bf 100644 --- a/src/SIL.Machine.AspNetCore/Configuration/MessageOutboxOptions.cs +++ b/src/SIL.Machine.AspNetCore/Configuration/MessageOutboxOptions.cs @@ -4,6 +4,6 @@ public class MessageOutboxOptions { public const string Key = "MessageOutbox"; - public string DataDir { get; set; } = "outbox"; + public string OutboxDir { get; set; } = "outbox"; public TimeSpan MessageExpirationTimeout { get; set; } = TimeSpan.FromHours(48); } diff --git a/src/SIL.Machine.AspNetCore/Services/MessageOutboxDeliveryService.cs b/src/SIL.Machine.AspNetCore/Services/MessageOutboxDeliveryService.cs index 7e4050f22..092f66913 100644 --- a/src/SIL.Machine.AspNetCore/Services/MessageOutboxDeliveryService.cs +++ b/src/SIL.Machine.AspNetCore/Services/MessageOutboxDeliveryService.cs @@ -19,6 +19,7 @@ ILogger logger protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + Initialize(); using IServiceScope scope = _services.CreateScope(); var messages = scope.ServiceProvider.GetRequiredService>(); using ISubscription subscription = await messages.SubscribeAsync(e => true, stoppingToken); @@ -31,6 +32,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } } + private void Initialize() + { + _fileSystem.CreateDirectory(_options.CurrentValue.OutboxDir); + } + internal async Task ProcessMessagesAsync( IRepository messages, CancellationToken cancellationToken = default @@ -99,7 +105,7 @@ private async Task ProcessGroupMessagesAsync( ) { Stream? contentStream = null; - string filePath = Path.Combine(_options.CurrentValue.DataDir, message.Id); + string filePath = Path.Combine(_options.CurrentValue.OutboxDir, message.Id); if (message.HasContentStream) contentStream = _fileSystem.OpenRead(filePath); try diff --git a/src/SIL.Machine.AspNetCore/Services/MessageOutboxService.cs b/src/SIL.Machine.AspNetCore/Services/MessageOutboxService.cs index 2383fcfbd..c69767d80 100644 --- a/src/SIL.Machine.AspNetCore/Services/MessageOutboxService.cs +++ b/src/SIL.Machine.AspNetCore/Services/MessageOutboxService.cs @@ -54,7 +54,7 @@ await _outboxes.UpdateAsync( Content = content, HasContentStream = contentStream is not null }; - string filePath = Path.Combine(_options.CurrentValue.DataDir, outboxMessage.Id); + string filePath = Path.Combine(_options.CurrentValue.OutboxDir, outboxMessage.Id); try { if (contentStream is not null) diff --git a/src/SIL.Machine.Serval.EngineServer/appsettings.json b/src/SIL.Machine.Serval.EngineServer/appsettings.json index 7d5b4cdf4..e5267100a 100644 --- a/src/SIL.Machine.Serval.EngineServer/appsettings.json +++ b/src/SIL.Machine.Serval.EngineServer/appsettings.json @@ -33,7 +33,8 @@ "BuildPollingEnabled": true }, "MessageOutbox": { - "MessageExpirationInHours": 48 + "MessageExpirationInHours": 48, + "OutboxDir": "/var/lib/machine/outbox" }, "Logging": { "LogLevel": { diff --git a/src/SIL.Machine.Serval.JobServer/appsettings.json b/src/SIL.Machine.Serval.JobServer/appsettings.json index 4ff49d691..ff0b0f54e 100644 --- a/src/SIL.Machine.Serval.JobServer/appsettings.json +++ b/src/SIL.Machine.Serval.JobServer/appsettings.json @@ -32,6 +32,10 @@ "ClearML": { "BuildPollingEnabled": false }, + "MessageOutbox": { + "MessageExpirationInHours": 48, + "OutboxDir": "/var/lib/machine/outbox" + }, "Logging": { "LogLevel": { "System.Net.Http.HttpClient.Default": "Warning"