< Summary

Information
Class: Elsa.Alterations.Services.BackgroundAlterationJobDispatcher
Assembly: Elsa.Alterations
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Services/BackgroundAlterationJobDispatcher.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 30
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%
DispatchAsync(...)100%11100%
ExecuteJobAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations/Services/BackgroundAlterationJobDispatcher.cs

#LineLine coverage
 1using Elsa.Alterations.Core.Contracts;
 2using Elsa.Common.Multitenancy;
 3using Elsa.Mediator.Contracts;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.Alterations.Services;
 7
 8/// <summary>
 9/// Dispatches an alteration job for execution using an in-memory channel.
 10/// </summary>
 511public class BackgroundAlterationJobDispatcher(
 512    IJobQueue jobQueue,
 513    ITenantAccessor tenantAccessor,
 514    ITenantScopeFactory tenantScopeFactory) : IAlterationJobDispatcher
 15{
 16    /// <inheritdoc />
 17    public ValueTask DispatchAsync(string jobId, CancellationToken cancellationToken = default)
 18    {
 519        var tenant = tenantAccessor.Tenant;
 1020        jobQueue.Enqueue(ct => ExecuteJobAsync(jobId, tenant, ct));
 521        return default;
 22    }
 23
 24    private async Task ExecuteJobAsync(string alterationJobId, Tenant? tenant, CancellationToken cancellationToken)
 25    {
 526        await using var tenantScope = tenantScopeFactory.CreateScope(tenant);
 527        var alterationJobRunner = tenantScope.ServiceProvider.GetRequiredService<IAlterationJobRunner>();
 528        await alterationJobRunner.RunAsync(alterationJobId, cancellationToken);
 429    }
 30}