< Summary

Information
Class: Services.OzonWebhookServices.Monitoring.OzonWebhookAvailabilityJob
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/OzonWebhookServices/Monitoring/OzonWebhookAvailabilityJob.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()100%66100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/OzonWebhookServices/Monitoring/OzonWebhookAvailabilityJob.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Threading.Tasks;
 4using Hangfire;
 5using Microsoft.Extensions.Logging;
 6using Services.HangfireService;
 7
 8namespace Services.OzonWebhookServices.Monitoring
 9{
 10    /// <summary>
 11    /// Периодически читает статусы доступности пуш-адресов из Ozon, обновляет снимок для баннера админа
 12    /// и пишет в лог предупреждение, когда набор проблем меняется.
 13    /// </summary>
 14    public sealed class OzonWebhookAvailabilityJob
 15    {
 16        public const string JobId = "ozon-webhook-availability";
 17        // Ozon замеряет раз в ночь; 30 минут — достаточно, чтобы быстро увидеть отключение и восстановление.
 18        public const string DefaultCron = "*/30 * * * *";
 19
 20        private readonly IOzonWebhookAvailabilityService _service;
 21        private readonly OzonWebhookAvailabilityStore _store;
 22        private readonly ILogger<OzonWebhookAvailabilityJob> _logger;
 23
 224        public OzonWebhookAvailabilityJob(
 225            IOzonWebhookAvailabilityService service,
 226            OzonWebhookAvailabilityStore store,
 227            ILogger<OzonWebhookAvailabilityJob> logger)
 28        {
 229            _service = service;
 230            _store = store;
 231            _logger = logger;
 232        }
 33
 34        [Queue(HangfireQueueNames.OrderStatusSync)]
 35        [DisableConcurrentExecution(timeoutInSeconds: 0)]
 36        [AutomaticRetry(Attempts = 0)]
 37        public async Task<string> ExecuteAsync()
 38        {
 339            var snapshot = await _service.RefreshAsync();
 340            var problems = snapshot.DescribeProblems();
 41
 342            if (_store.TryMarkAlerted(snapshot.ProblemSignature(), out _) && problems.Count > 0)
 143                _logger.LogWarning("Пуш-уведомления Ozon недоступны: {Problems}", string.Join("; ", problems));
 44
 345            return problems.Count == 0 ? "Все адреса доступны" : string.Join("; ", problems);
 346        }
 47    }
 48}