< Summary

Information
Class: Elsa.Workflows.Runtime.DefaultBookmarkQueuePurger
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultBookmarkQueuePurger.cs
Line coverage
4%
Covered lines: 1
Uncovered lines: 24
Coverable lines: 25
Total lines: 51
Line coverage: 4%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
PurgeAsync()0%620%

File(s)

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

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.Entities;
 3using Elsa.Common.Models;
 4using Elsa.Workflows.Runtime.Filters;
 5using Elsa.Workflows.Runtime.Options;
 6using Elsa.Workflows.Runtime.OrderDefinitions;
 7using JetBrains.Annotations;
 8using Microsoft.Extensions.Logging;
 9using Microsoft.Extensions.Options;
 10
 11namespace Elsa.Workflows.Runtime;
 12
 13[UsedImplicitly]
 514public class DefaultBookmarkQueuePurger(IBookmarkQueueStore store, ISystemClock systemClock, IOptions<BookmarkQueuePurge
 15{
 16    public async Task PurgeAsync(CancellationToken cancellationToken = default)
 17    {
 018        var currentPage = 0;
 019        var now = systemClock.UtcNow;
 020        var thresholdDate = now - options.Value.Ttl;
 21
 022        logger.LogDebug("Purging bookmark queue items older than {ThresholdDate}.", thresholdDate);
 23
 024        while (true)
 25        {
 026            var pageArgs = PageArgs.FromPage(currentPage, options.Value.BatchSize);
 027            var filter = new BookmarkQueueFilter
 028            {
 029                CreatedAtLessThan = thresholdDate
 030            };
 031            var order = new BookmarkQueueItemOrder<DateTimeOffset>(x => x.CreatedAt, OrderDirection.Ascending);
 032            var page = await store.PageAsync(pageArgs, filter, order, cancellationToken);
 033            var items = page.Items;
 34
 035            if (items.Count == 0)
 36                break;
 37
 038            var ids = items.Select(x => x.Id).ToList();
 039            await store.DeleteAsync(new BookmarkQueueFilter
 040            {
 041                Ids = ids
 042            }, cancellationToken);
 43
 044            logger.LogInformation("Purged {Count} bookmark queue items.", items.Count);
 45
 046            currentPage++;
 047        }
 48
 049        logger.LogDebug("Finished purging bookmark queue items.");
 050    }
 51}