Fix StartAt issue
This commit is contained in:
parent
409bf36e7e
commit
dd72ba3f14
|
|
@ -1,10 +1,12 @@
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Timers.ActivityResults;
|
||||
using Elsa.Activities.Timers.Services;
|
||||
using Elsa.ActivityResults;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Persistence;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NodaTime;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
|
|
@ -19,15 +21,13 @@ namespace Elsa.Activities.Timers
|
|||
)]
|
||||
public class StartAt : Activity
|
||||
{
|
||||
private readonly IWorkflowInstanceStore _workflowInstanceStore;
|
||||
private readonly IWorkflowScheduler _workflowScheduler;
|
||||
private readonly IClock _clock;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public StartAt(IWorkflowInstanceStore workflowInstanceStore, IWorkflowScheduler workflowScheduler, IClock clock)
|
||||
public StartAt(IClock clock, ILogger<StartAt> logger)
|
||||
{
|
||||
_workflowInstanceStore = workflowInstanceStore;
|
||||
_workflowScheduler = workflowScheduler;
|
||||
_clock = clock;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[ActivityProperty(Hint = "An instant in the future at which this activity should execute.")]
|
||||
|
|
@ -44,20 +44,18 @@ namespace Elsa.Activities.Timers
|
|||
if (context.WorkflowExecutionContext.IsFirstPass)
|
||||
return Done();
|
||||
|
||||
var cancellationToken = context.CancellationToken;
|
||||
var workflowBlueprint = context.WorkflowExecutionContext.WorkflowBlueprint;
|
||||
var workflowInstance = context.WorkflowExecutionContext.WorkflowInstance;
|
||||
var now = _clock.GetCurrentInstant();
|
||||
var executeAt = Instant;
|
||||
|
||||
ExecuteAt = executeAt;
|
||||
|
||||
if (executeAt <= _clock.GetCurrentInstant())
|
||||
if (executeAt <= now)
|
||||
{
|
||||
_logger.LogDebug("Scheduled trigger time lies in the past ('{Delta}'). Skipping scheduling.", now - ExecuteAt);
|
||||
return Done();
|
||||
}
|
||||
|
||||
await _workflowInstanceStore.SaveAsync(context.WorkflowExecutionContext.WorkflowInstance, cancellationToken);
|
||||
await _workflowScheduler.ScheduleWorkflowAsync(workflowBlueprint, workflowInstance.Id, Id, executeAt, cancellationToken);
|
||||
|
||||
return Suspend();
|
||||
return Combine(Suspend(), new ScheduleWorkflowResult(executeAt));
|
||||
}
|
||||
|
||||
protected override IActivityExecutionResult OnResume() => Done();
|
||||
|
|
|
|||
Loading…
Reference in a new issue