< Summary

Information
Class: Elsa.Scheduling.Activities.Cron
Assembly: Elsa.Scheduling
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Activities/Cron.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 66
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_CronExpression()100%11100%
ExecuteAsync()100%22100%
GetTriggerPayload(...)100%11100%
FromCronExpression(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Activities/Cron.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Extensions;
 3using Elsa.Scheduling.Bookmarks;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Attributes;
 6using Elsa.Workflows.Models;
 7
 8namespace Elsa.Scheduling.Activities;
 9
 10/// <summary>
 11/// Represents a timer to periodically trigger the workflow.
 12/// </summary>
 13[Activity("Elsa", "Scheduling", "Trigger workflow execution at a specific interval using a CRON expression.")]
 14public class Cron : EventGenerator
 15{
 16    /// <inheritdoc />
 3217    public Cron([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 18    {
 3219    }
 20
 21    /// <inheritdoc />
 2422    public Cron(string cronExpression, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : th
 23    {
 2424    }
 25
 26    /// <inheritdoc />
 2427    public Cron(Input<string> cronExpression, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = nul
 28    {
 2429        CronExpression = cronExpression;
 2430    }
 31
 32    /// <summary>
 33    /// The interval at which the timer should execute.
 34    /// </summary>
 35    [Input(Description = "The CRON expression at which the timer should execute.")]
 11636    public Input<string> CronExpression { get; set; } = null!;
 37
 38    /// <inheritdoc />
 39    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 40    {
 741        if(context.IsTriggerOfWorkflow())
 42        {
 143            await context.CompleteActivityAsync();
 144            return;
 45        }
 46
 647        var cronParser = context.GetRequiredService<ICronParser>();
 648        var cronExpression = context.ExpressionExecutionContext.Get(CronExpression)!;
 649        var executeAt = cronParser.GetNextOccurrence(cronExpression);
 50
 651        context.JournalData.Add("ExecuteAt", executeAt);
 652        context.CreateBookmark(new CronBookmarkPayload(executeAt, cronExpression));
 753    }
 54
 55    /// <inheritdoc />
 56    protected override object GetTriggerPayload(TriggerIndexingContext context)
 57    {
 658        var cronExpression = context.ExpressionExecutionContext.Get(CronExpression)!;
 659        return new CronTriggerPayload(cronExpression);
 60    }
 61
 62    /// <summary>
 63    /// Creates a new <see cref="Cron"/> activity set to trigger at the specified cron expression.
 64    /// </summary>
 2465    public static Cron FromCronExpression(string value, [CallerFilePath] string? source = null, [CallerLineNumber] int? 
 66}