Add logging to Timer

This commit is contained in:
Sipke Schoorstra 2021-01-03 19:19:03 +01:00
parent 4ce94ee01a
commit 1aee05d82f

View file

@ -3,6 +3,7 @@ using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Services;
using Elsa.Services.Models;
using Microsoft.Extensions.Logging;
using NodaTime;
// ReSharper disable once CheckNamespace
@ -12,10 +13,12 @@ namespace Elsa.Activities.Timers
public class Timer : Activity, IReschedule
{
private readonly IClock _clock;
private readonly ILogger _logger;
public Timer(IClock clock)
public Timer(IClock clock, ILogger<Timer> logger)
{
_clock = clock;
_logger = logger;
}
[ActivityProperty(Hint = "The time interval at which this activity should tick.")]
@ -34,9 +37,12 @@ namespace Elsa.Activities.Timers
var now = _clock.GetCurrentInstant();
ExecuteAt = now.Plus(Timeout);
if (ExecuteAt <= now)
{
_logger.LogDebug("Scheduled trigger time lies in the past ('{Delta}'). Skipping scheduling.", now - ExecuteAt);
return Done();
}
return Combine(Suspend(), new ScheduleWorkflowResult(ExecuteAt.Value));
}