< Summary

Information
Class: OzonOrdersWeb.WebServices.SystemAlerts.SystemMonitoringSignalService
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/SystemAlerts/SystemMonitoringSignalService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 41
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
RecordAsync()0%2040%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/SystemAlerts/SystemMonitoringSignalService.cs

#LineLine coverage
 1using Hangfire;
 2using Microsoft.EntityFrameworkCore;
 3using OzonDomains.Models;
 4using OzonRepositories.Context;
 5using Services.HangfireService;
 6
 7namespace OzonOrdersWeb.WebServices.SystemAlerts;
 8
 9public interface ISystemMonitoringSignalService
 10{
 11    Task RecordAsync(string sourceKey, string outcome, string? scopeKey = null, string? message = null, CancellationToke
 12}
 13
 014public sealed class SystemMonitoringSignalService(ApplicationDbContext context) : ISystemMonitoringSignalService
 15{
 16    public async Task RecordAsync(string sourceKey, string outcome, string? scopeKey = null, string? message = null, Can
 17    {
 018        context.SystemMonitoringSignals.Add(new SystemMonitoringSignal
 019        {
 020            SourceKey = sourceKey[..Math.Min(100, sourceKey.Length)], Outcome = outcome[..Math.Min(16, outcome.Length)],
 021            ScopeKey = scopeKey?[..Math.Min(120, scopeKey.Length)], Message = message?[..Math.Min(500, message.Length)]
 022        });
 023        await context.SaveChangesAsync(cancellationToken);
 024    }
 25}
 26
 27public sealed class SystemMonitoringSignalCleanupJob(ApplicationDbContext context)
 28{
 29    public const string JobId = "system-monitoring-signal-cleanup";
 30    public const string DefaultCron = "30 3 * * *";
 31    [Queue(HangfireQueueNames.Main)]
 32    public async Task ExecuteAsync()
 33    {
 34        var threshold = DateTime.UtcNow.AddDays(-RetentionDays);
 35        await context.SystemMonitoringSignals.Where(x => x.OccurredAtUtc < threshold).ExecuteDeleteAsync();
 36        // Закрытые инциденты тоже не копим бесконечно; активные не трогаем.
 37        await context.SystemAlertIncidents.Where(x => !x.IsActive && x.LastObservedAtUtc < threshold).ExecuteDeleteAsync
 38    }
 39
 40    private const int RetentionDays = 90;
 41}