тдщп
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using PepperBot.Application.Interfaces;
|
||||
using PepperBot.Domain;
|
||||
|
||||
@@ -6,11 +6,12 @@ namespace PepperBot.Application.Services;
|
||||
|
||||
public class DealService
|
||||
{
|
||||
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IPepperClient _pepperClient;
|
||||
private readonly IDealRepository _repository;
|
||||
private readonly ISubscriptionRepository _subscriptionRepository;
|
||||
private readonly ITelegramNotifier _notifier;
|
||||
private readonly ILogger<DealService> _logger;
|
||||
private readonly IHealthMonitor _healthMonitor;
|
||||
|
||||
public DealService(
|
||||
@@ -18,14 +19,12 @@ public class DealService
|
||||
IDealRepository repository,
|
||||
ISubscriptionRepository subscriptionRepository,
|
||||
ITelegramNotifier notifier,
|
||||
ILogger<DealService> logger,
|
||||
IHealthMonitor healthMonitor)
|
||||
{
|
||||
_pepperClient = pepperClient;
|
||||
_repository = repository;
|
||||
_subscriptionRepository = subscriptionRepository;
|
||||
_notifier = notifier;
|
||||
_logger = logger;
|
||||
_healthMonitor = healthMonitor;
|
||||
}
|
||||
|
||||
@@ -33,28 +32,28 @@ public class DealService
|
||||
{
|
||||
var deals = await _pepperClient.GetLatestDealsAsync(cancellationToken);
|
||||
|
||||
_logger.LogInformation("Начата обработка полученных скидок: всего {DealCount}", deals.Count);
|
||||
Logger.Info("Начата обработка полученных скидок: всего {DealCount}", deals.Count);
|
||||
|
||||
// Хелсчек: успешный запрос, вернувший более одной скидки (пусть и не новой)
|
||||
if (deals.Count > 1)
|
||||
{
|
||||
_healthMonitor.ReportSuccess(DateTimeOffset.UtcNow);
|
||||
_logger.LogDebug("HealthCheck: успешно получено более одной скидки ({DealCount})", deals.Count);
|
||||
Logger.Debug("HealthCheck: успешно получено более одной скидки ({DealCount})", deals.Count);
|
||||
}
|
||||
|
||||
// Загружаем активные подписки один раз на проход
|
||||
var subscriptions = await _subscriptionRepository.GetAllActiveAsync(cancellationToken);
|
||||
_logger.LogInformation("Загружено активных подписок: {SubscriptionCount}", subscriptions.Count);
|
||||
Logger.Info("Загружено активных подписок: {SubscriptionCount}", subscriptions.Count);
|
||||
|
||||
foreach (var deal in deals)
|
||||
{
|
||||
if (await _repository.ExistsAsync(deal.Id, cancellationToken))
|
||||
{
|
||||
_logger.LogDebug("Скидка уже есть в репозитории и будет пропущена: {DealId}", deal.Id);
|
||||
Logger.Debug("Скидка уже есть в репозитории и будет пропущена: {DealId}", deal.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Новая скидка: {Title} ({Id})", deal.Title, deal.Id);
|
||||
Logger.Info("Новая скидка: {Title} ({Id})", deal.Title, deal.Id);
|
||||
|
||||
await _repository.AddAsync(deal, cancellationToken);
|
||||
|
||||
@@ -63,7 +62,7 @@ public class DealService
|
||||
|
||||
if (subscriptions.Count == 0)
|
||||
{
|
||||
_logger.LogDebug("Активные подписки отсутствуют. Фильтрация по ключевым словам пропущена для скидки {DealId}", deal.Id);
|
||||
Logger.Debug("Активные подписки отсутствуют. Фильтрация по ключевым словам пропущена для скидки {DealId}", deal.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -73,21 +72,21 @@ public class DealService
|
||||
{
|
||||
if (!subscription.IsActive)
|
||||
{
|
||||
_logger.LogDebug("Подписка {SubscriptionId} неактивна и будет пропущена", subscription.Id);
|
||||
Logger.Debug("Подписка {SubscriptionId} неактивна и будет пропущена", subscription.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
var keywords = ParseKeywords(subscription.Keywords);
|
||||
if (keywords.Count == 0)
|
||||
{
|
||||
_logger.LogDebug("У подписки {SubscriptionId} не удалось извлечь ключевые слова из строки: \"{RawKeywords}\"",
|
||||
Logger.Debug("У подписки {SubscriptionId} не удалось извлечь ключевые слова из строки: \"{RawKeywords}\"",
|
||||
subscription.Id,
|
||||
subscription.Keywords);
|
||||
continue;
|
||||
}
|
||||
|
||||
var isMatch = IsMatch(searchableText, keywords);
|
||||
_logger.LogDebug(
|
||||
Logger.Debug(
|
||||
"Результат фильтрации скидки {DealId} по подписке {SubscriptionId}: {IsMatch}. Текст: \"{Text}\"; ключевые слова: {Keywords}",
|
||||
deal.Id,
|
||||
subscription.Id,
|
||||
|
||||
Reference in New Issue
Block a user