< Summary

Information
Class: Elsa.Extensions.TimerActivityExecutionContextExtensions
Assembly: Elsa.Scheduling
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Extensions/TimerActivityExecutionContextExtensions.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 45
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RepeatWithInterval(...)100%44100%
GetTimerTriggerStimulus(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Extensions/TimerActivityExecutionContextExtensions.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Scheduling;
 3using Elsa.Scheduling.Bookmarks;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Models;
 6
 7// ReSharper disable once CheckNamespace
 8namespace Elsa.Extensions;
 9
 10public static class TimerActivityExecutionContextExtensions
 11{
 12    /// <summary>
 13    /// Repeats the execution of the current activity at the specified interval.
 14    /// </summary>
 15    /// <param name="context">The execution context of the activity.</param>
 16    /// <param name="interval">The time interval after which the activity should be repeated.</param>
 17    /// <param name="callback">An optional callback to execute immediately if the workflow is triggered.</param>
 18    public static void RepeatWithInterval(this ActivityExecutionContext context, TimeSpan interval, ExecuteActivityDeleg
 19    {
 1220        if(context.IsTriggerOfWorkflow())
 21        {
 222            callback?.Invoke(context);
 223            return;
 24        }
 25
 1026        var clock = context.ExpressionExecutionContext.GetRequiredService<ISystemClock>();
 1027        var resumeAt = clock.UtcNow.Add(interval);
 28
 1029        var bookmarkOptions = new CreateBookmarkArgs
 1030        {
 1031            BookmarkName = SchedulingStimulusNames.Timer,
 1032            Stimulus = new TimerBookmarkPayload(resumeAt),
 1033            Callback = callback
 1034        };
 1035        context.CreateBookmark(bookmarkOptions);
 1036    }
 37
 38    public static TimerTriggerPayload GetTimerTriggerStimulus(this TriggerIndexingContext context, TimeSpan interval)
 39    {
 440        var clock = context.ExpressionExecutionContext.GetRequiredService<ISystemClock>();
 441        var executeAt = clock.UtcNow.Add(interval);
 442        context.TriggerName = SchedulingStimulusNames.Timer;
 443        return new(executeAt, interval);
 44    }
 45}