2022-01-04 08:42:12 +00:00
|
|
|
|
using System;
|
2022-01-13 21:38:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
using Elsa.Attributes;
|
2022-01-13 21:38:01 +00:00
|
|
|
|
using Elsa.Contracts;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
using Elsa.Models;
|
|
|
|
|
|
|
2022-02-01 19:45:11 +00:00
|
|
|
|
namespace Elsa.Modules.Scheduling.Triggers;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
2022-01-17 21:44:41 +00:00
|
|
|
|
/// <summary>
|
2022-03-07 11:01:27 +00:00
|
|
|
|
/// Represents a timer to periodically trigger the workflow.
|
2022-01-17 21:44:41 +00:00
|
|
|
|
/// </summary>
|
2022-03-07 11:01:27 +00:00
|
|
|
|
public class Timer : EventGenerator
|
2022-01-04 08:42:12 +00:00
|
|
|
|
{
|
|
|
|
|
|
[Input] public Input<TimeSpan> Interval { get; set; } = default!;
|
2022-01-13 21:38:01 +00:00
|
|
|
|
|
2022-03-07 11:01:27 +00:00
|
|
|
|
protected override IEnumerable<object> GetTriggerData(TriggerIndexingContext context)
|
2022-01-13 21:38:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
var interval = context.ExpressionExecutionContext.Get(Interval);
|
|
|
|
|
|
var clock = context.ExpressionExecutionContext.GetRequiredService<ISystemClock>();
|
|
|
|
|
|
var executeAt = clock.UtcNow.Add(interval);
|
2022-01-14 12:54:17 +00:00
|
|
|
|
yield return new TimerPayload(executeAt, interval);
|
2022-01-13 21:38:01 +00:00
|
|
|
|
}
|
2022-01-14 12:54:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 21:56:16 +00:00
|
|
|
|
public record TimerPayload(DateTimeOffset StartAt, TimeSpan Interval);
|