feat(bll): IntervalService - сервис для функций которые нужно выполнить в интервале, применена к Master, EsppOrderLoader.
This commit is contained in:
29
PARR.BLL/Services/Implementations/IntervalService.cs
Normal file
29
PARR.BLL/Services/Implementations/IntervalService.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
internal class IntervalService : IIntervalService
|
||||
{
|
||||
private readonly ILogger<IntervalService> logger;
|
||||
|
||||
public IntervalService(ILogger<IntervalService> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public async Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
logger.LogInformation($"Запуск по расписанию. Интервал: {interval}");
|
||||
|
||||
await intervalHandler.Invoke();
|
||||
|
||||
logger.LogInformation($"Следующая дата запуска: {DateTimeOffset.Now.Add(interval)}");
|
||||
|
||||
await Task.Delay(interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user