< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.RegistrationDispatcher
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Email/RegistrationDispatcher.cs
Line coverage
94%
Covered lines: 16
Uncovered lines: 1
Coverable lines: 17
Total lines: 44
Line coverage: 94.1%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage
100%
Covered methods: 3
Fully covered methods: 2
Total methods: 3
Method coverage: 100%
Full method coverage: 66.6%

Metrics

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

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/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>
 96911public sealed class RegistrationDispatcher(
 96912    RegistrationQueue queue,
 96913    IServiceScopeFactory scopeFactory,
 96914    ILogger<RegistrationDispatcher> logger) : BackgroundService
 15{
 16    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 17    {
 18        try
 19        {
 199020            await foreach (var request in queue.Reader.ReadAllAsync(stoppingToken))
 21            {
 2722                await ProcessAsync(request);
 23            }
 024        }
 96825        catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
 26        {
 27            // Shutdown. Whatever is still queued is dropped, as in the recovery queue.
 96828        }
 96829    }
 30
 31    private async Task ProcessAsync(RegistrationRequest request)
 32    {
 33        try
 34        {
 2735            await using var scope = scopeFactory.CreateAsyncScope();
 36
 2737            await scope.ServiceProvider.GetRequiredService<RegistrationProcessor>().ProcessAsync(request);
 2638        }
 139        catch (Exception exception)
 40        {
 141            logger.LogError(exception, "A registration request could not be processed");
 142        }
 2743    }
 44}