< Summary

Information
Class: Anichron.Worker.Work.StorageConfigSchedules<T>
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Work/StorageConfigSchedules.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 26
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
SchedulesAsync()100%22100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Work/StorageConfigSchedules.cs

#LineLine coverage
 1using Anichron.Core.Data.Repository;
 2using Anichron.Core.Work;
 3using Anichron.Worker.Settings;
 4using Microsoft.Extensions.Options;
 5using NodaTime;
 6
 7namespace Anichron.Worker.Work;
 8
 9/// <summary>One schedule per active storage config the Worker serves, at the crawl interval.</summary>
 10/// <typeparam name="TPayload">The per-config kind scheduled.</typeparam>
 11/// <param name="workerState">Names the user a per-user Worker serves.</param>
 12/// <param name="options">Supplies the crawl interval.</param>
 713public sealed class StorageConfigSchedules<TPayload>(WorkerState workerState, IOptions<WorkerSettings> options)
 14    : IWorkScheduleSource
 15    where TPayload : IStorageConfigPayload<TPayload>
 16{
 17    public async Task<IReadOnlyList<IWorkSchedule>> SchedulesAsync(IServiceProvider services, CancellationToken ct)
 418    {
 419        var repository = services.GetRequiredService<IUserStorageConfigRepository>();
 420        var served = workerState.ResolvedUserId is { } userId
 421            ? await repository.GetActiveByUserIdAsync(userId, ct)
 422            : await repository.GetAllActiveAsync(ct);
 423        var interval = Duration.FromHours(options.Value.CrawlIntervalHours);
 424        return [.. served.Select(config => new WorkSchedule<TPayload>(TPayload.For(config.Id), interval))];
 425    }
 26}