Extract auto-Done scheduling to a handler
This commit is contained in:
parent
937b861359
commit
5ed136a41f
|
|
@ -0,0 +1,3 @@
|
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<ConfigureAwait />
|
||||
</Weavers>
|
||||
|
|
@ -27,10 +27,6 @@ namespace Elsa.ActivityResults
|
|||
var workflowExecutionContext = activityExecutionContext.WorkflowExecutionContext;
|
||||
var nextConnections = GetNextConnections(workflowExecutionContext, activityExecutionContext.ActivityBlueprint.Id, outcomes).ToList();
|
||||
|
||||
// Always try if we got a "default" connection (from the current activity to the next activity via the default "Done" outcome).
|
||||
if (!outcomes.Contains(OutcomeNames.Done) && !nextConnections.Any())
|
||||
nextConnections = GetNextConnections(workflowExecutionContext, activityExecutionContext.ActivityBlueprint.Id, new[] { OutcomeNames.Done }).ToList();
|
||||
|
||||
var nextActivities =
|
||||
(
|
||||
from connection in nextConnections
|
||||
|
|
@ -47,15 +43,15 @@ namespace Elsa.ActivityResults
|
|||
}
|
||||
|
||||
public static IEnumerable<string> GetNextActivities(
|
||||
WorkflowExecutionContext workflowContext,
|
||||
WorkflowExecutionContext workflowExecutionContext,
|
||||
string sourceId,
|
||||
IEnumerable<string> outcomes)
|
||||
{
|
||||
var nextConnections = GetNextConnections(workflowContext, sourceId, outcomes);
|
||||
var nextConnections = GetNextConnections(workflowExecutionContext, sourceId, outcomes);
|
||||
|
||||
var query =
|
||||
from connection in nextConnections
|
||||
from activityBlueprint in workflowContext.WorkflowBlueprint.Activities
|
||||
from activityBlueprint in workflowExecutionContext.WorkflowBlueprint.Activities
|
||||
where activityBlueprint.Id == connection.Target.Activity.Id
|
||||
select activityBlueprint.Id;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.ActivityResults;
|
||||
using Elsa.Events;
|
||||
using MediatR;
|
||||
|
||||
namespace Elsa.Handlers
|
||||
{
|
||||
public class ConnectNextActivityViaDefaultOutcome : INotificationHandler<WorkflowExecutionBurstCompleted>
|
||||
{
|
||||
public Task Handle(WorkflowExecutionBurstCompleted notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var activityExecutionContext = notification.ActivityExecutionContext;
|
||||
var workflowExecutionContext = activityExecutionContext.WorkflowExecutionContext;
|
||||
|
||||
// Check to see if there are connections with the last-executed activity's "Done" outcome.
|
||||
// This handles the case for workflows built using the WorkflowBuilder API where activities are chained, expecting the chained activities to execute next, regardless of the activity's outcome.
|
||||
|
||||
var nextActivities = OutcomeResult.GetNextActivities(workflowExecutionContext, activityExecutionContext.ActivityId, new[] {OutcomeNames.Done}).ToList();
|
||||
workflowExecutionContext.ScheduleActivities(nextActivities, activityExecutionContext.Output);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue