< Summary

Information
Class: Elsa.Workflows.Runtime.ActivityExecutionStatsService
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/ActivityExecutionService.cs
Line coverage
8%
Covered lines: 3
Uncovered lines: 33
Coverable lines: 36
Total lines: 62
Line coverage: 8.3%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetStatsAsync()0%620%
GetStatsAsync()0%620%

File(s)

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

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Workflows.Runtime.Filters;
 3using Elsa.Workflows.Runtime.OrderDefinitions;
 4
 5namespace Elsa.Workflows.Runtime;
 6
 7/// <inheritdoc />
 8public class ActivityExecutionStatsService : IActivityExecutionStatsService
 9{
 10    private readonly IActivityExecutionStore _store;
 11
 12    /// <summary>
 13    /// Initializes a new instance of the <see cref="ActivityExecutionStatsService"/> class.
 14    /// </summary>
 115    public ActivityExecutionStatsService(IActivityExecutionStore store)
 16    {
 117        _store = store;
 118    }
 19
 20    /// <inheritdoc />
 21    public async Task<IEnumerable<ActivityExecutionStats>> GetStatsAsync(string workflowInstanceId, IEnumerable<string> 
 22    {
 023        var filter = new ActivityExecutionRecordFilter
 024        {
 025            WorkflowInstanceId = workflowInstanceId,
 026            ActivityNodeIds = activityNodeIds?.ToList()
 027        };
 028        var order = new ActivityExecutionRecordOrder<DateTimeOffset>(x => x.StartedAt, OrderDirection.Ascending);
 029        var records = (await _store.FindManySummariesAsync(filter, order, cancellationToken)).ToList();
 030        var groupedRecords = records.GroupBy(x => x.ActivityNodeId).ToList();
 031        var stats = groupedRecords.Select(grouping =>
 032        {
 033            var first = grouping.First();
 034            var last = grouping.Last();
 035            return new ActivityExecutionStats
 036            {
 037                ActivityNodeId = grouping.Key,
 038                ActivityId = first.ActivityId,
 039                StartedCount = grouping.Count(),
 040                CompletedCount = grouping.Count(x => x.CompletedAt != null),
 041                UncompletedCount = grouping.Count(x => x.CompletedAt == null),
 042                IsBlocked = grouping.Any(x => x.HasBookmarks),
 043                IsFaulted = grouping.Any(x => x.Status == ActivityStatus.Faulted),
 044                AggregateFaultCount = last.AggregateFaultCount,
 045                Metadata = last.Metadata
 046            };
 047        }).ToList();
 48
 049        return stats;
 050    }
 51
 52    /// <inheritdoc />
 53    public async Task<ActivityExecutionStats> GetStatsAsync(string workflowInstanceId, string activityNodeId, Cancellati
 54    {
 055        var stats = (await GetStatsAsync(workflowInstanceId, [activityNodeId], cancellationToken)).FirstOrDefault();
 56
 057        return stats ?? new ActivityExecutionStats
 058        {
 059            ActivityNodeId = activityNodeId
 060        };
 061    }
 62}