руфдер
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
namespace PepperBot.Application.Interfaces;
|
||||
|
||||
public interface IHealthMonitor
|
||||
{
|
||||
/// <summary>
|
||||
/// Отметить успешный запрос к Pepper, вернувший более одной скидки.
|
||||
/// </summary>
|
||||
/// <param name="timestamp">Время успешного запроса (UTC).</param>
|
||||
void ReportSuccess(DateTimeOffset timestamp);
|
||||
|
||||
/// <summary>
|
||||
/// Время последнего успешного запроса или null, если их ещё не было.
|
||||
/// </summary>
|
||||
DateTimeOffset? LastSuccessfulRequestAt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Текущее состояние healthcheck.
|
||||
/// </summary>
|
||||
bool IsHealthy(TimeSpan successTtl);
|
||||
}
|
||||
|
||||
@@ -10,23 +10,32 @@ public class DealService
|
||||
private readonly IDealRepository _repository;
|
||||
private readonly ITelegramNotifier _notifier;
|
||||
private readonly ILogger<DealService> _logger;
|
||||
private readonly IHealthMonitor _healthMonitor;
|
||||
|
||||
public DealService(
|
||||
IPepperClient pepperClient,
|
||||
IDealRepository repository,
|
||||
ITelegramNotifier notifier,
|
||||
ILogger<DealService> logger)
|
||||
ILogger<DealService> logger,
|
||||
IHealthMonitor healthMonitor)
|
||||
{
|
||||
_pepperClient = pepperClient;
|
||||
_repository = repository;
|
||||
_notifier = notifier;
|
||||
_logger = logger;
|
||||
_healthMonitor = healthMonitor;
|
||||
}
|
||||
|
||||
public async Task CheckAndNotifyAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var deals = await _pepperClient.GetLatestDealsAsync(cancellationToken);
|
||||
|
||||
// Хелсчек: успешный запрос, вернувший более одной скидки (пусть и не новой)
|
||||
if (deals.Count > 1)
|
||||
{
|
||||
_healthMonitor.ReportSuccess(DateTimeOffset.UtcNow);
|
||||
}
|
||||
|
||||
foreach (var deal in deals)
|
||||
{
|
||||
if (await _repository.ExistsAsync(deal.Id, cancellationToken))
|
||||
|
||||
Reference in New Issue
Block a user