| | | 1 | | using Anichron.Core.Data.Repository; |
| | | 2 | | using Anichron.Core.Domain; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Worker.Work; |
| | | 5 | | |
| | | 6 | | /// <summary>The result of a per-config item whose storage config is missing or inactive.</summary> |
| | | 7 | | /// <param name="Reason">Why nothing was done.</param> |
| | | 8 | | public sealed record StorageConfigSkipped(string Reason) |
| | | 9 | | { |
| | 6 | 10 | | public static StorageConfigSkipped MissingOrInactive => new("The storage config is missing or inactive."); |
| | | 11 | | } |
| | | 12 | | |
| | | 13 | | internal sealed partial class ActiveStorageConfigs( |
| | | 14 | | IUserStorageConfigRepository configs, |
| | | 15 | | ILogger<ActiveStorageConfigs> logger) |
| | | 16 | | { |
| | | 17 | | /// <summary>The config, or null (logged) when it is missing or inactive and the item is skipped.</summary> |
| | | 18 | | /// <param name="kind">The kind of the item asking.</param> |
| | | 19 | | /// <param name="storageConfigId">The item's storage config.</param> |
| | | 20 | | /// <param name="ct">Cancels the lookup.</param> |
| | | 21 | | public async Task<UserStorageConfig?> FindAsync(WorkKind kind, Guid storageConfigId, CancellationToken ct) |
| | | 22 | | { |
| | | 23 | | if (await configs.FindByIdAsync(storageConfigId, ct) is { IsActive: true } config) |
| | | 24 | | return config; |
| | | 25 | | |
| | | 26 | | Log.Skipped(logger, kind, storageConfigId); |
| | | 27 | | return null; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | private static partial class Log |
| | | 31 | | { |
| | | 32 | | [LoggerMessage(Level = LogLevel.Information, Message = "Skipping {Kind} of storage config {Id}: it is missing or |
| | | 33 | | public static partial void Skipped(ILogger logger, WorkKind kind, Guid id); |
| | | 34 | | } |
| | | 35 | | } |