< Summary

Information
Class: Elsa.Scheduling.Activities.StartAt
Assembly: Elsa.Scheduling
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Scheduling/Activities/StartAt.cs
Line coverage
58%
Covered lines: 20
Uncovered lines: 14
Coverable lines: 34
Total lines: 107
Line coverage: 58.8%
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
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%11100%
.ctor(...)100%210%
get_DateTime()100%11100%
GetTriggerPayload(...)100%210%
ExecuteAsync()100%44100%
From(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Common;
 3using Elsa.Expressions.Models;
 4using Elsa.Extensions;
 5using Elsa.Scheduling.Bookmarks;
 6using Elsa.Workflows;
 7using Elsa.Workflows.Attributes;
 8using Elsa.Workflows.Memory;
 9using Elsa.Workflows.Models;
 10using Microsoft.Extensions.Logging;
 11
 12namespace Elsa.Scheduling.Activities;
 13
 14/// <summary>
 15/// Triggers the workflow at a specific future timestamp.
 16/// </summary>
 17[Activity("Elsa", "Scheduling", "Trigger execution at a specific time in the future.")]
 18public class StartAt : Trigger
 19{
 20    private const string InputKey = "ExecuteAt";
 21
 22    /// <inheritdoc />
 2323    public StartAt([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 24    {
 2325    }
 26
 27    /// <inheritdoc />
 028    public StartAt(Input<DateTimeOffset> dateTime, [CallerFilePath] string? source = null, [CallerLineNumber] int? line 
 29
 30    /// <inheritdoc />
 31    public StartAt(Func<ExpressionExecutionContext, DateTimeOffset> dateTime, [CallerFilePath] string? source = null, [C
 032        : this(new Input<DateTimeOffset>(dateTime), source, line)
 33    {
 034    }
 35
 36    /// <inheritdoc />
 37    public StartAt(
 38        Func<ExpressionExecutionContext, ValueTask<DateTimeOffset>> dateTime,
 039        [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(new Input<DateTimeOffset>(da
 40    {
 041    }
 42
 43    /// <inheritdoc />
 44    public StartAt(Func<ValueTask<DateTimeOffset>> dateTime, [CallerFilePath] string? source = null, [CallerLineNumber] 
 045        : this(new Input<DateTimeOffset>(dateTime), source, line)
 46    {
 047    }
 48
 49    /// <inheritdoc />
 50    public StartAt(Func<DateTimeOffset> dateTime, [CallerFilePath] string? source = null, [CallerLineNumber] int? line =
 051        : this(new Input<DateTimeOffset>(dateTime), source, line)
 52    {
 053    }
 54
 55    /// <inheritdoc />
 2356    public StartAt(DateTimeOffset dateTime, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 2357        DateTime = new Input<DateTimeOffset>(dateTime);
 58
 59    /// <inheritdoc />
 060    public StartAt(Variable<DateTimeOffset> dateTime, [CallerFilePath] string? source = null, [CallerLineNumber] int? li
 061        DateTime = new Input<DateTimeOffset>(dateTime);
 62
 63    /// <summary>
 64    /// The timestamp at which the workflow should be triggered.
 65    /// </summary>
 66    [Input]
 8467    public Input<DateTimeOffset> DateTime { get; set; } = null!;
 68
 69    /// <inheritdoc />
 70    protected override object GetTriggerPayload(TriggerIndexingContext context)
 71    {
 072        var executeAt = context.ExpressionExecutionContext.Get(DateTime);
 073        return new StartAtPayload(executeAt);
 74    }
 75
 76    /// <inheritdoc />
 77    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 78    {
 679        if (context.IsTriggerOfWorkflow())
 80        {
 181            await context.CompleteActivityAsync();
 182            return;
 83        }
 84
 585        var executeAt = context.ExpressionExecutionContext.Get(DateTime);
 586        var clock = context.ExpressionExecutionContext.GetRequiredService<ISystemClock>();
 587        var now = clock.UtcNow;
 588        var logger = context.GetRequiredService<ILogger<StartAt>>();
 89
 590        context.JournalData.Add("Executed At", now);
 91
 592        if (executeAt <= now)
 93        {
 294            logger.LogDebug("Scheduled trigger time lies in the past ('{Delta}'). Completing immediately", now - execute
 295            await context.CompleteActivityAsync();
 296            return;
 97        }
 98
 399        var payload = new StartAtPayload(executeAt);
 3100        context.CreateBookmark(payload);
 6101    }
 102
 103    /// <summary>
 104    /// Creates a new <see cref="StartAt"/> activity set to trigger at the specified timestamp.
 105    /// </summary>
 0106    public static StartAt From(DateTimeOffset value, [CallerFilePath] string? source = null, [CallerLineNumber] int? lin
 107}