From ef39263f82937c124ff9fb211ceec1998596eb50 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 16 Nov 2026 16:51:46 +0100 Subject: [PATCH] Refactor ConsumerInitWorker to use IHostedService Refactored the `ConsumerInitWorker` class to implement the `IHostedService` interface, replacing `BackgroundService`. Replaced `ExecuteAsync` with `StartAsync` and `StopAsync` methods. Added a log statement for successful initialization of `SendingEmailConsumerPool`. Updated `DigitalData.MessagingService.API.csproj` to increment version numbers: - `Version`: 2.2.0-beta -> 2.2.1-beta - `FileVersion`: 2.2.0.0 -> 2.2.1.0 - `AssemblyVersion`: 2.2.0.0 -> 2.2.1.0 These changes introduce minor improvements and bug fixes without breaking changes. --- .../Services/Background/ConsumerInitWorker.cs | 13 +++++++------ .../DigitalData.MessagingService.API.csproj | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/Background/ConsumerInitWorker.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/Background/ConsumerInitWorker.cs index 47ab803..372fd58 100644 --- a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/Background/ConsumerInitWorker.cs +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Services/Background/ConsumerInitWorker.cs @@ -15,17 +15,18 @@ public class ConsumerInitWorker( SendingEmailConsumerPool ConsumerPool, ILogger Logger, IOptions RabbitMqOptions, - ConsumerInitHealthCheck HealthCheck) : BackgroundService + ConsumerInitHealthCheck HealthCheck) : IHostedService { - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + public async Task StartAsync(CancellationToken cancellationToken) { try { await ConsumerPool.InitAsync(); + Logger.LogInformation("SendingEmailConsumerPool initialized successfully."); } catch (Exception ex) { - // Log and mark the health check as unhealthy — callers will receive HTTP 503. + // Log and mark the health check as unhealthy � callers will receive HTTP 503. // The API remains operational; only outgoing email delivery via the consumer pool is affected. Logger.LogError(ex, "Failed to initialize SendingEmailConsumerPool. Outgoing email consumers are not running."); @@ -34,7 +35,7 @@ public class ConsumerInitWorker( if (!RabbitMqOptions.Value.ContinueOnInitFailure) throw; } - - await Task.Delay(Timeout.Infinite, stoppingToken).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); } -} \ No newline at end of file + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; +} diff --git a/src/presentation/DigitalData.MessagingService.API/DigitalData.MessagingService.API.csproj b/src/presentation/DigitalData.MessagingService.API/DigitalData.MessagingService.API.csproj index f06f072..d3b5fdd 100644 --- a/src/presentation/DigitalData.MessagingService.API/DigitalData.MessagingService.API.csproj +++ b/src/presentation/DigitalData.MessagingService.API/DigitalData.MessagingService.API.csproj @@ -10,9 +10,9 @@ Digital Data GmbH Digital Data GmbH DigitalData.MessagingService.API - 2.2.0-beta - 2.2.0.0 - 2.2.0.0 + 2.2.1-beta + 2.2.1.0 + 2.2.1.0 Copyright © 2026 Digital Data GmbH. All rights reserved. bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml