< Summary

Information
Class: Elsa.Workflows.Runtime.WorkflowDefinitionsRefresher
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/WorkflowDefinitionRefresher.cs
Line coverage
96%
Covered lines: 26
Uncovered lines: 1
Coverable lines: 27
Total lines: 57
Line coverage: 96.2%
Branch coverage
71%
Covered branches: 10
Total branches: 14
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
RefreshWorkflowDefinitionsAsync()66.66%121295.45%
IndexWorkflowTriggersAsync()100%22100%

File(s)

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

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Common.Models;
 3using Elsa.Mediator.Contracts;
 4using Elsa.Workflows.Management;
 5using Elsa.Workflows.Management.Entities;
 6using Elsa.Workflows.Management.Filters;
 7using Elsa.Workflows.Runtime.Notifications;
 8using Elsa.Workflows.Runtime.Requests;
 9using Elsa.Workflows.Runtime.Responses;
 10
 11namespace Elsa.Workflows.Runtime;
 12
 13/// <inheritdoc />
 214public class WorkflowDefinitionsRefresher(IWorkflowDefinitionStore store, ITriggerIndexer triggerIndexer, INotificationS
 15{
 16    /// <inheritdoc />
 17    public async Task<RefreshWorkflowDefinitionsResponse> RefreshWorkflowDefinitionsAsync(RefreshWorkflowDefinitionsRequ
 18    {
 119        var filter = new WorkflowDefinitionFilter
 120        {
 121            DefinitionIds = request.DefinitionIds,
 122            VersionOptions = VersionOptions.Published
 123        };
 24
 125        var currentPage = 0;
 126        var processedWorkflowDefinitions = new List<WorkflowDefinition>();
 127        var batchSize = request.BatchSize;
 128        var order = new WorkflowDefinitionOrder<string>(x => x.Id, OrderDirection.Ascending);
 29
 130        while (!cancellationToken.IsCancellationRequested)
 31        {
 132            var pageArgs = PageArgs.FromPage(currentPage, batchSize);
 133            var definitions = await store.FindManyAsync(filter, order, pageArgs, cancellationToken);
 34
 135            if (definitions.Items.Count == 0)
 36                break;
 37
 138            await IndexWorkflowTriggersAsync(definitions.Items, cancellationToken);
 139            processedWorkflowDefinitions.AddRange(definitions.Items);
 140            currentPage++;
 41
 142            if (definitions.Items.Count < batchSize)
 43                break;
 044        }
 45
 246        var processedWorkflowDefinitionIds = processedWorkflowDefinitions.Select(x => x.DefinitionId).ToList();
 147        var notification = new WorkflowDefinitionsRefreshed(processedWorkflowDefinitionIds);
 148        await notificationSender.SendAsync(notification, cancellationToken);
 149        return new(processedWorkflowDefinitionIds, request.DefinitionIds?.Except(processedWorkflowDefinitionIds)?.ToList
 150    }
 51
 52    private async Task IndexWorkflowTriggersAsync(IEnumerable<WorkflowDefinition> definitions, CancellationToken cancell
 53    {
 454        foreach (var definition in definitions)
 155            await triggerIndexer.IndexTriggersAsync(definition, cancellationToken);
 156    }
 57}