< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.RegistrationDispatcher
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/RegistrationDispatcher.cs
Line coverage
76%
Covered lines: 13
Uncovered lines: 4
Coverable lines: 17
Total lines: 44
Line coverage: 76.4%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage
100%
Covered methods: 3
Fully covered methods: 1
Total methods: 3
Method coverage: 100%
Full method coverage: 33.3%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()50%2283.33%
ProcessAsync()100%1157.14%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/RegistrationDispatcher.cs

#LineLine coverage
 1using ArturRios.Heimdall.Command.Services;
 2
 3namespace ArturRios.Heimdall.WebApi.Email;
 4
 5/// <summary>
 6///     Works through <see cref="RegistrationQueue" />: one fresh DI scope and one
 7///     <see cref="RegistrationProcessor" /> run per request, after the caller has been answered. One
 8///     request at a time; a failure is logged and the next request taken. See
 9///     <see cref="PasswordRecoveryDispatcher" />, which this mirrors.
 10/// </summary>
 89911public sealed class RegistrationDispatcher(
 89912    RegistrationQueue queue,
 89913    IServiceScopeFactory scopeFactory,
 89914    ILogger<RegistrationDispatcher> logger) : BackgroundService
 15{
 16    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 17    {
 18        try
 19        {
 183820            await foreach (var request in queue.Reader.ReadAllAsync(stoppingToken))
 21            {
 2022                await ProcessAsync(request);
 23            }
 024        }
 89925        catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
 26        {
 27            // Shutdown. Whatever is still queued is dropped, as in the recovery queue.
 89928        }
 89929    }
 30
 31    private async Task ProcessAsync(RegistrationRequest request)
 32    {
 33        try
 34        {
 2035            await using var scope = scopeFactory.CreateAsyncScope();
 36
 2037            await scope.ServiceProvider.GetRequiredService<RegistrationProcessor>().ProcessAsync(request);
 2038        }
 039        catch (Exception exception)
 40        {
 041            logger.LogError(exception, "A registration request could not be processed");
 042        }
 2043    }
 44}