< Summary

Information
Class: Services.FidSupplierLinkServices.FidSupplierLinkDiscoveryJob
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FidSupplierLinkServices/FidSupplierLinkDiscoveryJob.cs
Line coverage
84%
Covered lines: 16
Uncovered lines: 3
Coverable lines: 19
Total lines: 46
Line coverage: 84.2%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.1%
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()57.14%151481.25%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FidSupplierLinkServices/FidSupplierLinkDiscoveryJob.cs

#LineLine coverage
 1using Hangfire;
 2using Microsoft.Extensions.Logging;
 3using Services.SignalRServices;
 4using Services.SystemMonitoringServices;
 5
 6namespace Services.FidSupplierLinkServices;
 7
 8public sealed class FidSupplierLinkDiscoveryJob
 9{
 10    public const string JobId = "fid-supplier-link-discovery";
 11    public const string DefaultCron = "0 */3 * * *";
 12    private readonly FidSupplierLinkService _links;
 13    private readonly FidSuppliersFeedCache _feed;
 14    private readonly ILogger<FidSupplierLinkDiscoveryJob> _logger;
 15    private readonly ISystemMonitoringSignalWriter? _signals;
 16
 417    public FidSupplierLinkDiscoveryJob(FidSupplierLinkService links, FidSuppliersFeedCache feed, ILogger<FidSupplierLink
 2018    { _links = links; _feed = feed; _logger = logger; _signals = signals; }
 19
 20    [DisableConcurrentExecution(timeoutInSeconds: 0)]
 21    public async Task<string> ExecuteAsync()
 22    {
 423        var (feed, error) = await _feed.GetAsync(forceRefresh: true);
 624        if (feed is null) { _logger.LogWarning("{JobId}: {Error}", JobId, error); return error ?? "Фид недоступен"; }
 25        try
 26        {
 327            await _links.SyncDiscoveredAsync(feed);
 328            await (_signals?.RecordAsync("fid-suppliers-mapping", "success") ?? Task.CompletedTask);
 329        }
 030        catch
 31        {
 032            await (_signals?.RecordAsync("fid-suppliers-mapping", "failure", message: "Ошибка сопоставления поставщиков 
 033            throw;
 34        }
 335        var pending = await _links.GetPendingNotificationsAsync(TimeSpan.FromDays(7));
 436        if (pending.Count == 0) return "Новых несвязанных поставщиков фида нет.";
 837        var names = pending.Select(x => x.FidSupplierName).OrderBy(x => x).ToArray();
 38        try
 39        {
 240            await NotificationService.NotifyAsync("Связи фида", "#D97706", "Несвязанные поставщики фида: " + string.Join
 141            await _links.MarkNotifiedAsync(names);
 142        }
 343        catch (Exception ex) { _logger.LogWarning(ex, "{JobId}: не удалось отправить уведомление", JobId); }
 244        return $"Несвязанных поставщиков: {names.Length}";
 445    }
 46}