< Summary

Information
Class: Elsa.Scheduling.Services.DefaultBookmarkScheduler
Assembly: Elsa.Scheduling
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Services/DefaultBookmarkScheduler.cs
Line coverage
69%
Covered lines: 73
Uncovered lines: 32
Coverable lines: 105
Total lines: 174
Line coverage: 69.5%
Branch coverage
80%
Covered branches: 16
Total branches: 20
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ScheduleAsync()50%36823.8%
ScheduleAsync()100%88100%
UnscheduleAsync()100%22100%
UnscheduleAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Services/DefaultBookmarkScheduler.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Scheduling.Bookmarks;
 3using Elsa.Workflows.Models;
 4using Elsa.Workflows.Runtime.Entities;
 5
 6namespace Elsa.Scheduling.Services;
 7
 8/// <summary>
 9/// A default implementation of <see cref="ITriggerScheduler"/> that schedules bookmarks using <see cref="IWorkflowSched
 10/// </summary>
 11public class DefaultBookmarkScheduler : IBookmarkScheduler
 12{
 13    private readonly IWorkflowScheduler _workflowScheduler;
 14
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="DefaultBookmarkScheduler"/> class.
 17    /// </summary>
 45318    public DefaultBookmarkScheduler(IWorkflowScheduler workflowScheduler)
 19    {
 45320        _workflowScheduler = workflowScheduler;
 45321    }
 22
 23    /// <inheritdoc />
 24    public async Task ScheduleAsync(IEnumerable<StoredBookmark> bookmarks, CancellationToken cancellationToken = default
 25    {
 226        var bookmarkList = bookmarks.ToList();
 227        var delayBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Delay);
 228        var startAtBookmarks = bookmarkList.Filter(SchedulingStimulusNames.StartAt);
 229        var timerBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Timer);
 230        var cronBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Cron);
 31
 32        // Schedule each Delay bookmark.
 433        foreach (var bookmark in delayBookmarks)
 34        {
 035            var payload = bookmark.GetPayload<DelayPayload>();
 036            var resumeAt = payload.ResumeAt;
 037            var request = new ScheduleExistingWorkflowInstanceRequest
 038            {
 039                WorkflowInstanceId = bookmark.WorkflowInstanceId,
 040                BookmarkId = bookmark.Id
 041            };
 042            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, resumeAt, cancellationToken);
 43        }
 44
 45        // Schedule each StartAt bookmark.
 446        foreach (var bookmark in startAtBookmarks)
 47        {
 048            var payload = bookmark.GetPayload<StartAtPayload>();
 049            var executeAt = payload.ExecuteAt;
 050            var request = new ScheduleExistingWorkflowInstanceRequest
 051            {
 052                WorkflowInstanceId = bookmark.WorkflowInstanceId,
 053                BookmarkId = bookmark.Id
 054            };
 055            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, executeAt, cancellationToken);
 56        }
 57
 58        // Schedule each Timer bookmark.
 459        foreach (var bookmark in timerBookmarks)
 60        {
 061            var payload = bookmark.GetPayload<TimerBookmarkPayload>();
 062            var resumeAt = payload.ResumeAt;
 063            var request = new ScheduleExistingWorkflowInstanceRequest
 064            {
 065                WorkflowInstanceId = bookmark.WorkflowInstanceId,
 066                BookmarkId = bookmark.Id
 067            };
 068            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, resumeAt, cancellationToken);
 69        }
 70
 71        // Schedule each Cron bookmark.
 472        foreach (var bookmark in cronBookmarks)
 73        {
 074            var payload = bookmark.GetPayload<CronBookmarkPayload>();
 075            var cronExpression = payload.CronExpression;
 076            var request = new ScheduleExistingWorkflowInstanceRequest
 077            {
 078                WorkflowInstanceId = bookmark.WorkflowInstanceId,
 079                BookmarkId = bookmark.Id
 080            };
 081            await _workflowScheduler.ScheduleCronAsync(bookmark.Id, request, cronExpression, cancellationToken);
 82        }
 283    }
 84
 85    /// <inheritdoc />
 86    public async Task ScheduleAsync(string workflowInstanceId, IEnumerable<Bookmark> bookmarks, CancellationToken cancel
 87    {
 45788        var bookmarkList = bookmarks.ToList();
 45789        var delayBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Delay);
 45790        var startAtBookmarks = bookmarkList.Filter(SchedulingStimulusNames.StartAt);
 45791        var timerBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Timer);
 45792        var cronBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Cron);
 93
 94        // Schedule each Delay bookmark.
 94495        foreach (var bookmark in delayBookmarks)
 96        {
 1597            var payload = bookmark.GetPayload<DelayPayload>();
 1598            var resumeAt = payload.ResumeAt;
 1599            var request = new ScheduleExistingWorkflowInstanceRequest
 15100            {
 15101                WorkflowInstanceId = workflowInstanceId,
 15102                BookmarkId = bookmark.Id
 15103            };
 15104            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, resumeAt, cancellationToken);
 105        }
 106
 107        // Schedule each StartAt bookmark.
 916108        foreach (var bookmark in startAtBookmarks)
 109        {
 1110            var payload = bookmark.GetPayload<StartAtPayload>();
 1111            var executeAt = payload.ExecuteAt;
 1112            var request = new ScheduleExistingWorkflowInstanceRequest
 1113            {
 1114                WorkflowInstanceId = workflowInstanceId,
 1115                BookmarkId = bookmark.Id
 1116            };
 1117            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, executeAt, cancellationToken);
 118        }
 119
 120        // Schedule each Timer bookmark.
 916121        foreach (var bookmark in timerBookmarks)
 122        {
 1123            var payload = bookmark.GetPayload<TimerBookmarkPayload>();
 1124            var resumeAt = payload.ResumeAt;
 1125            var request = new ScheduleExistingWorkflowInstanceRequest
 1126            {
 1127                WorkflowInstanceId = workflowInstanceId,
 1128                BookmarkId = bookmark.Id
 1129            };
 1130            await _workflowScheduler.ScheduleAtAsync(bookmark.Id, request, resumeAt, cancellationToken);
 131        }
 132
 133        // Schedule each Cron bookmark.
 916134        foreach (var bookmark in cronBookmarks)
 135        {
 1136            var payload = bookmark.GetPayload<CronBookmarkPayload>();
 1137            var cronExpression = payload.CronExpression;
 1138            var request = new ScheduleExistingWorkflowInstanceRequest
 1139            {
 1140                WorkflowInstanceId = workflowInstanceId,
 1141                BookmarkId = bookmark.Id
 1142            };
 1143            await _workflowScheduler.ScheduleCronAsync(bookmark.Id, request, cronExpression, cancellationToken);
 144        }
 457145    }
 146
 147    /// <inheritdoc />
 148    public async Task UnscheduleAsync(IEnumerable<Bookmark> bookmarks, CancellationToken cancellationToken = default)
 149    {
 457150        var bookmarkList = bookmarks.ToList();
 457151        var delayBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Delay);
 457152        var startAtBookmarks = bookmarkList.Filter(SchedulingStimulusNames.StartAt);
 457153        var timerBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Timer);
 457154        var cronBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Cron);
 457155        var bookmarksToUnSchedule = delayBookmarks.Concat(startAtBookmarks).Concat(timerBookmarks).Concat(cronBookmarks)
 156
 942157        foreach (var bookmark in bookmarksToUnSchedule)
 14158            await _workflowScheduler.UnscheduleAsync(bookmark.Id, cancellationToken);
 457159    }
 160
 161    /// <inheritdoc />
 162    public async Task UnscheduleAsync(IEnumerable<StoredBookmark> bookmarks, CancellationToken cancellationToken = defau
 163    {
 52164        var bookmarkList = bookmarks.ToList();
 52165        var delayBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Delay);
 52166        var startAtBookmarks = bookmarkList.Filter(SchedulingStimulusNames.StartAt);
 52167        var timerBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Timer);
 52168        var cronBookmarks = bookmarkList.Filter(SchedulingStimulusNames.Cron);
 52169        var bookmarksToUnSchedule = delayBookmarks.Concat(startAtBookmarks).Concat(timerBookmarks).Concat(cronBookmarks)
 170
 140171        foreach (var bookmark in bookmarksToUnSchedule)
 18172            await _workflowScheduler.UnscheduleAsync(bookmark.Id, cancellationToken);
 52173    }
 174}