< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

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
 14public sealed class SystemMonitoringSignalService(ApplicationDbContext context) : ISystemMonitoringSignalService
 15{
 16    public async Task RecordAsync(string sourceKey, string outcome, string? scopeKey = null, string? message = null, Can
 17    {
 18        context.SystemMonitoringSignals.Add(new SystemMonitoringSignal
 19        {
 20            SourceKey = sourceKey[..Math.Min(100, sourceKey.Length)], Outcome = outcome[..Math.Min(16, outcome.Length)],
 21            ScopeKey = scopeKey?[..Math.Min(120, scopeKey.Length)], Message = message?[..Math.Min(500, message.Length)]
 22        });
 23        await context.SaveChangesAsync(cancellationToken);
 24    }
 25}
 26
 027public 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    {
 034        var threshold = DateTime.UtcNow.AddDays(-RetentionDays);
 035        await context.SystemMonitoringSignals.Where(x => x.OccurredAtUtc < threshold).ExecuteDeleteAsync();
 36        // Закрытые инциденты тоже не копим бесконечно; активные не трогаем.
 037        await context.SystemAlertIncidents.Where(x => !x.IsActive && x.LastObservedAtUtc < threshold).ExecuteDeleteAsync
 038    }
 39
 40    private const int RetentionDays = 90;
 41}