< Summary

Information
Class: Anichron.Worker.Settings.WorkerSettings
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Settings/WorkerSettings.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 123
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ExcludedDirectoryNames()100%11100%
Validate(...)100%44100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Settings/WorkerSettings.cs

#LineLine coverage
 1using Anichron.Infrastructure.Configuration;
 2using System.ComponentModel.DataAnnotations;
 3
 4namespace Anichron.Worker.Settings;
 5
 6public sealed record WorkerSettings : IValidatableObject
 7{
 8    // Stryker disable once String
 9    public string User { get; init; } = string.Empty;
 10
 11    // Stryker disable once String
 12    public string RootPath { get; init; } = string.Empty;
 13
 14    public string ExcludedDirectories { get; init; } = string.Empty;
 15
 16    [Range(1, int.MaxValue)]
 17    public int CrawlIntervalHours { get; init; } = 4;
 18
 19    [Range(1, int.MaxValue)]
 20    public int MaxConcurrentFiles { get; init; } = 4;
 21
 22    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 23    public double TokenCleanupIntervalHours { get; init; } = 24;
 24
 25    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 26    public double WorkPollIntervalSeconds { get; init; } = 5;
 27
 28    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 29    public double WorkHeartbeatSeconds { get; init; } = 2;
 30
 31    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 32    public double WorkLeaseSeconds { get; init; } = 60;
 33
 34    [Range(1, int.MaxValue)]
 35    public int WorkMaxStalls { get; init; } = 3;
 36
 37    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 38    public double WorkItemRetentionDays { get; init; } = 30;
 39
 40    [Range(0.0, double.MaxValue, MinimumIsExclusive = true)]
 41    public double WorkItemRetentionIntervalHours { get; init; } = 24;
 42
 43    [Range(1, int.MaxValue)]
 44    public int BurstGapSeconds { get; init; } = 120;
 45
 46    [Range(1, int.MaxValue)]
 47    public int BurstSpanSeconds { get; init; } = 300;
 48
 49    [Range(0.0, 1.0, MinimumIsExclusive = true)]
 50    public double BurstSimilarityThreshold { get; init; } = 0.25;
 51
 52    [Range(1, int.MaxValue)]
 53    public int ThumbnailShortEdge { get; init; } = 300;
 54
 55    [Range(1, 100)]
 56    public int ThumbnailJpegQuality { get; init; } = 75;
 57
 58    [Range(1, int.MaxValue)]
 59    public int PreviewLongEdge { get; init; } = 1920;
 60
 61    [Range(1, 100)]
 62    public int PreviewJpegQuality { get; init; } = 85;
 63
 64    /// <summary>
 65    /// The long edge of a compact preview. A change sizes only compact previews made afterwards, as
 66    /// <see cref="VideoShortEdge"/>.
 67    /// </summary>
 68    [Range(1, int.MaxValue)]
 69    public int CompactPreviewLongEdge { get; init; } = 1280;
 70
 71    [Range(0, 100)]
 72    public int CompactPreviewQuality { get; init; } = 85;
 73
 74    [Range(3, 9)]
 75    public int CompactPreviewEffort { get; init; } = 7;
 76
 77    [Range(1, int.MaxValue)]
 78    public int CompactPreviewChunkSize { get; init; } = 200;
 79
 80    [Range(1, int.MaxValue)]
 81    public int BlurhashSampleLongEdge { get; init; } = 64;
 82
 83    [Required]
 84    public string FfmpegPath { get; init; } = "ffmpeg";
 85
 86    /// <summary>
 87    /// The short edge of a video proxy. A change sizes only videos ingested afterwards; an existing proxy keeps its
 88    /// size until its file changes.
 89    /// </summary>
 90    [Range(1, int.MaxValue)]
 91    public int VideoShortEdge { get; init; } = 720;
 92
 93    [Range(1, int.MaxValue)]
 94    public int VideoBitrateKbps { get; init; } = 2000;
 95
 96    public IReadOnlyList<string> ExcludedDirectoryNames()
 9697        => ConfigurationList.Parse(ExcludedDirectories, static name => name);
 98
 99    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 19100    {
 19101        var failures = ExcludedDirectoryNames()
 19102            .Where(name => name.IndexOfAny(['/', '\\']) >= 0)
 19103            .Select(name => new ValidationResult(
 19104                $"Worker:ExcludedDirectories takes folder names, not paths: '{name}'.",
 19105                [nameof(ExcludedDirectories)]))
 19106            .ToList();
 19107        if (WorkLeaseSeconds / 2 <= 2 * WorkHeartbeatSeconds)
 4108        {
 4109            failures.Add(new ValidationResult(
 4110                "Worker:WorkLeaseSeconds must be longer than four times Worker:WorkHeartbeatSeconds: a running item stop
 4111                [nameof(WorkLeaseSeconds)]));
 4112        }
 113
 19114        if (BurstSpanSeconds < BurstGapSeconds)
 2115        {
 2116            failures.Add(new ValidationResult(
 2117                "Worker:BurstSpanSeconds must be at least Worker:BurstGapSeconds, or no neighbour further away than the 
 2118                [nameof(BurstSpanSeconds)]));
 2119        }
 120
 19121        return failures;
 19122    }
 123}