| | | 1 | | using Anichron.Infrastructure.Configuration; |
| | | 2 | | using System.ComponentModel.DataAnnotations; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Worker.Settings; |
| | | 5 | | |
| | | 6 | | public 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() |
| | 96 | 97 | | => ConfigurationList.Parse(ExcludedDirectories, static name => name); |
| | | 98 | | |
| | | 99 | | public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) |
| | 19 | 100 | | { |
| | 19 | 101 | | var failures = ExcludedDirectoryNames() |
| | 19 | 102 | | .Where(name => name.IndexOfAny(['/', '\\']) >= 0) |
| | 19 | 103 | | .Select(name => new ValidationResult( |
| | 19 | 104 | | $"Worker:ExcludedDirectories takes folder names, not paths: '{name}'.", |
| | 19 | 105 | | [nameof(ExcludedDirectories)])) |
| | 19 | 106 | | .ToList(); |
| | 19 | 107 | | if (WorkLeaseSeconds / 2 <= 2 * WorkHeartbeatSeconds) |
| | 4 | 108 | | { |
| | 4 | 109 | | failures.Add(new ValidationResult( |
| | 4 | 110 | | "Worker:WorkLeaseSeconds must be longer than four times Worker:WorkHeartbeatSeconds: a running item stop |
| | 4 | 111 | | [nameof(WorkLeaseSeconds)])); |
| | 4 | 112 | | } |
| | | 113 | | |
| | 19 | 114 | | if (BurstSpanSeconds < BurstGapSeconds) |
| | 2 | 115 | | { |
| | 2 | 116 | | failures.Add(new ValidationResult( |
| | 2 | 117 | | "Worker:BurstSpanSeconds must be at least Worker:BurstGapSeconds, or no neighbour further away than the |
| | 2 | 118 | | [nameof(BurstSpanSeconds)])); |
| | 2 | 119 | | } |
| | | 120 | | |
| | 19 | 121 | | return failures; |
| | 19 | 122 | | } |
| | | 123 | | } |