Initial import of the CBDDC codebase with docs and tests. Add a .NET-focused gitignore to keep generated artifacts out of source control.
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
62
src/ZB.MOM.WW.CBDDC.Hosting/HostedServices/DiscoveryServiceHostedService.cs
Executable file
62
src/ZB.MOM.WW.CBDDC.Hosting/HostedServices/DiscoveryServiceHostedService.cs
Executable file
@@ -0,0 +1,62 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using ZB.MOM.WW.CBDDC.Network;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Hosting.HostedServices;
|
||||
|
||||
/// <summary>
|
||||
/// Hosted service that manages the lifecycle of the discovery service.
|
||||
/// </summary>
|
||||
public class DiscoveryServiceHostedService : IHostedService
|
||||
{
|
||||
private readonly IDiscoveryService _discoveryService;
|
||||
private readonly ILogger<DiscoveryServiceHostedService> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DiscoveryServiceHostedService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="discoveryService">The discovery service to manage.</param>
|
||||
/// <param name="logger">The logger used for service lifecycle events.</param>
|
||||
public DiscoveryServiceHostedService(
|
||||
IDiscoveryService discoveryService,
|
||||
ILogger<DiscoveryServiceHostedService> logger)
|
||||
{
|
||||
_discoveryService = discoveryService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the discovery service.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A token used to cancel the startup operation.</param>
|
||||
/// <returns>A task that represents the asynchronous start operation.</returns>
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using var serviceContext = LogContext.PushProperty("Service", nameof(DiscoveryServiceHostedService));
|
||||
using var operationContext = LogContext.PushProperty("OperationId", Guid.NewGuid().ToString("N"));
|
||||
using var actionContext = LogContext.PushProperty("Action", "Start");
|
||||
|
||||
_logger.LogInformation("Starting Discovery Service...");
|
||||
await _discoveryService.Start();
|
||||
_logger.LogInformation("Discovery Service started");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the discovery service.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A token used to cancel the shutdown operation.</param>
|
||||
/// <returns>A task that represents the asynchronous stop operation.</returns>
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using var serviceContext = LogContext.PushProperty("Service", nameof(DiscoveryServiceHostedService));
|
||||
using var operationContext = LogContext.PushProperty("OperationId", Guid.NewGuid().ToString("N"));
|
||||
using var actionContext = LogContext.PushProperty("Action", "Stop");
|
||||
|
||||
_logger.LogInformation("Stopping Discovery Service...");
|
||||
await _discoveryService.Stop();
|
||||
_logger.LogInformation("Discovery Service stopped");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user