< Summary

Information
Class: Elsa.Workflows.Runtime.LocalBackgroundActivityScheduler
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/LocalBackgroundActivityScheduler.cs
Line coverage
73%
Covered lines: 11
Uncovered lines: 4
Coverable lines: 15
Total lines: 49
Line coverage: 73.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CreateAsync(...)100%11100%
ScheduleAsync(...)100%11100%
ScheduleAsync(...)100%210%
UnscheduledAsync(...)100%11100%
CancelAsync(...)100%210%
InvokeBackgroundActivity()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/LocalBackgroundActivityScheduler.cs

#LineLine coverage
 1using Elsa.Mediator.Contracts;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace Elsa.Workflows.Runtime;
 5
 6/// <summary>
 7/// Invokes activities from a background worker within the context of its workflow instance using a local background wor
 8/// </summary>
 1419public class LocalBackgroundActivityScheduler(IJobQueue jobQueue, IServiceScopeFactory scopeFactory) : IBackgroundActivi
 10{
 11    public Task<string> CreateAsync(ScheduledBackgroundActivity scheduledBackgroundActivity, CancellationToken cancellat
 12    {
 613        var jobId = jobQueue.Create(async ct => await InvokeBackgroundActivity(scheduledBackgroundActivity, ct));
 314        return Task.FromResult(jobId);
 15    }
 16
 17    public Task ScheduleAsync(string jobId, CancellationToken cancellationToken = default)
 18    {
 319        jobQueue.Enqueue(jobId);
 320        return Task.CompletedTask;
 21    }
 22
 23    /// <inheritdoc />
 24    public Task<string> ScheduleAsync(ScheduledBackgroundActivity scheduledBackgroundActivity, CancellationToken cancell
 25    {
 026        var jobId = jobQueue.Enqueue(async ct => await InvokeBackgroundActivity(scheduledBackgroundActivity, ct));
 027        return Task.FromResult(jobId);
 28    }
 29
 30    public Task UnscheduledAsync(string jobId, CancellationToken cancellationToken = default)
 31    {
 332        jobQueue.Dequeue(jobId);
 333        return Task.CompletedTask;
 34    }
 35
 36    /// <inheritdoc />
 37    public Task CancelAsync(string jobId, CancellationToken cancellationToken = default)
 38    {
 039        jobQueue.Cancel(jobId);
 040        return Task.CompletedTask;
 41    }
 42
 43    private async Task InvokeBackgroundActivity(ScheduledBackgroundActivity scheduledBackgroundActivity, CancellationTok
 44    {
 345        using var scope = scopeFactory.CreateScope();
 346        var backgroundActivityInvoker = scope.ServiceProvider.GetRequiredService<IBackgroundActivityInvoker>();
 347        await backgroundActivityInvoker.ExecuteAsync(scheduledBackgroundActivity, cancellationToken);
 348    }
 49}