Optimize timer activities to always execute when target time stamp lies in past
This commit is contained in:
parent
8078e7bccc
commit
f5f9c070ca
|
|
@ -49,6 +49,9 @@ namespace Elsa.Activities.Timers
|
|||
|
||||
ExecuteAt = executeAt;
|
||||
|
||||
if (executeAt < _clock.GetCurrentInstant())
|
||||
return Done();
|
||||
|
||||
await _workflowInstanceStore.SaveAsync(context.WorkflowExecutionContext.WorkflowInstance, cancellationToken);
|
||||
await _workflowScheduler.ScheduleWorkflowAsync(workflowBlueprint, workflowInstance.Id, Id, executeAt, cancellationToken);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,11 +21,13 @@ namespace Elsa.Activities.Timers
|
|||
{
|
||||
private readonly IWorkflowInstanceStore _workflowInstanceStore;
|
||||
private readonly IWorkflowScheduler _workflowScheduler;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public StartAt(IWorkflowInstanceStore workflowInstanceStore, IWorkflowScheduler workflowScheduler)
|
||||
public StartAt(IWorkflowInstanceStore workflowInstanceStore, IWorkflowScheduler workflowScheduler, IClock clock)
|
||||
{
|
||||
_workflowInstanceStore = workflowInstanceStore;
|
||||
_workflowScheduler = workflowScheduler;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
[ActivityProperty(Hint = "An instant in the future at which this activity should execute.")]
|
||||
|
|
@ -49,6 +51,9 @@ namespace Elsa.Activities.Timers
|
|||
|
||||
ExecuteAt = executeAt;
|
||||
|
||||
if (executeAt <= _clock.GetCurrentInstant())
|
||||
return Done();
|
||||
|
||||
await _workflowInstanceStore.SaveAsync(context.WorkflowExecutionContext.WorkflowInstance, cancellationToken);
|
||||
await _workflowScheduler.ScheduleWorkflowAsync(workflowBlueprint, workflowInstance.Id, Id, executeAt, cancellationToken);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Elsa.Activities.Timers
|
|||
if (context.WorkflowExecutionContext.IsFirstPass)
|
||||
return Done();
|
||||
|
||||
if (Timeout == Duration.Zero)
|
||||
if (Timeout <= Duration.Zero)
|
||||
return Done();
|
||||
|
||||
ExecuteAt = _clock.GetCurrentInstant().Plus(Timeout);
|
||||
|
|
|
|||
Loading…
Reference in a new issue