< Summary

Information
Class: Elsa.Common.Multitenancy.TaskExecutor
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Implementations/TaskExecutor.cs
Line coverage
86%
Covered lines: 13
Uncovered lines: 2
Coverable lines: 15
Total lines: 42
Line coverage: 86.6%
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%
ExecuteTaskAsync()100%11100%
StartAsync()100%11100%
StopAsync()100%210%
ExecuteInternalAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Implementations/TaskExecutor.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Common.DistributedHosting;
 3using Elsa.Common.RecurringTasks;
 4using Medallion.Threading;
 5using Microsoft.Extensions.Options;
 6
 7namespace Elsa.Common.Multitenancy;
 8
 29public class TaskExecutor(IDistributedLockProvider distributedLockProvider, IOptions<DistributedLockingOptions> options)
 10{
 11    public async Task ExecuteTaskAsync(ITask task, CancellationToken cancellationToken)
 12    {
 2413        await ExecuteInternalAsync(task, () => task.ExecuteAsync(cancellationToken), cancellationToken);
 1214    }
 15
 16    public async Task StartAsync(IBackgroundTask task, CancellationToken cancellationToken)
 17    {
 218        await ExecuteInternalAsync(task, () => task.StartAsync(cancellationToken), cancellationToken);
 119    }
 20
 21    public async Task StopAsync(IBackgroundTask task, CancellationToken cancellationToken)
 22    {
 023        await ExecuteInternalAsync(task, () => task.StopAsync(cancellationToken), cancellationToken);
 024    }
 25
 26    private async Task ExecuteInternalAsync(ITask task, Func<Task> action, CancellationToken cancellationToken)
 27    {
 1328        var taskType = task.GetType();
 1329        var singleNodeTask = taskType.GetCustomAttribute<SingleNodeTaskAttribute>() != null;
 30
 1331        if (singleNodeTask)
 32        {
 933            var resourceName = taskType.AssemblyQualifiedName!;
 934            await using (await distributedLockProvider.AcquireLockAsync(resourceName, options.Value.LockAcquisitionTimeo
 935                await action();
 36        }
 37        else
 38        {
 439            await action();
 40        }
 1341    }
 42}