Add AuctionBackgroundService, MgBackgroundServiceBase, OnDateTimeReceive

This commit is contained in:
Loretta 2024-12-12 20:18:41 +01:00
parent 3178b031e4
commit 6d4e09d49c
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
using Microsoft.Extensions.Hosting;
using Nop.Services.Logging;
namespace Mango.Nop.Services;
public abstract class MgBackgroundServiceBase(ILogger logger, IServiceProvider service) : BackgroundService
{
protected abstract Task OnExecuteAsync();
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
try
{
await logger.InformationAsync($"MgBackgroundServiceBase.ExecuteAsync(); Processing ExecuteAsync");
await OnExecuteAsync();
}
catch (Exception ex)
{
await logger.ErrorAsync($"MgBackgroundServiceBase.ExecuteAsync(); Failure while processing ExecuteAsync", ex, null);
}
}
}
public override async Task StartAsync(CancellationToken cancellationToken)
{
await logger.InformationAsync("MgBackgroundServiceBase.ExecuteAsync(); Starting MgBackgroundServiceBase");
await base.StartAsync(cancellationToken);
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
await logger.InformationAsync("MgBackgroundServiceBase.StopAsync(); Stopping MgBackgroundServiceBase");
await base.StopAsync(cancellationToken);
}
}