Merge remote-tracking branch 'origin/develop/3.5.0' into develop/3.6.0
This commit is contained in:
commit
8ce841df9a
|
|
@ -8,10 +8,6 @@
|
|||
<NoWarn>$(NoWarn);CS0162;CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ElsaStudioVersion>3.5.0-preview.1040</ElsaStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ConfigureAwait.Fody" PrivateAssets="All"/>
|
||||
<PackageReference Include="Fody" PrivateAssets="All"/>
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public static class WorkflowExecutionContextExtensions
|
|||
public static ActivityWorkItem ScheduleActivityExecutionContext(this WorkflowExecutionContext workflowExecutionContext, ActivityExecutionContext activityExecutionContext, IDictionary<string, object>? input = null, IEnumerable<Variable>? variables = null)
|
||||
{
|
||||
var workItem = new ActivityWorkItem(
|
||||
activityExecutionContext.Activity,
|
||||
input: input,
|
||||
activityExecutionContext.Activity,
|
||||
input: input,
|
||||
variables: variables,
|
||||
existingActivityExecutionContext: activityExecutionContext);
|
||||
workflowExecutionContext.Scheduler.Schedule(workItem);
|
||||
|
|
@ -112,7 +112,7 @@ public static class WorkflowExecutionContextExtensions
|
|||
// Validate that the specified activity is part of the workflow.
|
||||
if (!workflowExecutionContext.NodeActivityLookup.ContainsKey(activityNode.Activity))
|
||||
throw new InvalidOperationException("The specified activity is not part of the workflow.");
|
||||
|
||||
|
||||
var scheduler = workflowExecutionContext.Scheduler;
|
||||
|
||||
if (options?.PreventDuplicateScheduling == true)
|
||||
|
|
@ -145,4 +145,21 @@ public static class WorkflowExecutionContextExtensions
|
|||
var outputRegister = workflowExecutionContext.GetActivityOutputRegister();
|
||||
return outputRegister.FindOutputByActivityId(activityId, outputName);
|
||||
}
|
||||
|
||||
public static IEnumerable<ActivityExecutionContext> FindActivityExecutionContexts(this WorkflowExecutionContext workflowExecutionContext, ActivityHandle activityHandle)
|
||||
{
|
||||
if (activityHandle.ActivityInstanceId != null)
|
||||
return workflowExecutionContext.ActivityExecutionContexts.Where(x => x.Id == activityHandle.ActivityInstanceId);
|
||||
if (activityHandle.ActivityNodeId != null)
|
||||
return workflowExecutionContext.ActivityExecutionContexts.Where(x => x.NodeId == activityHandle.ActivityNodeId);
|
||||
if (activityHandle.ActivityId != null)
|
||||
return workflowExecutionContext.ActivityExecutionContexts.Where(x => x.Activity.Id == activityHandle.ActivityId);
|
||||
if (activityHandle.ActivityHash != null)
|
||||
{
|
||||
var activity = workflowExecutionContext.FindActivityByHash(activityHandle.ActivityHash);
|
||||
return activity != null ? workflowExecutionContext.ActivityExecutionContexts.Where(x => x.Activity.NodeId == activity.NodeId) : [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
using Elsa.Common;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Models;
|
||||
using Elsa.Workflows.Pipelines.ActivityExecution;
|
||||
using Elsa.Workflows.State;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Elsa.Workflows.Middleware.Activities;
|
||||
|
|
@ -34,34 +32,14 @@ public class ExceptionHandlingMiddleware(ActivityMiddlewareDelegate next, IIncid
|
|||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning(e, "An exception was caught from a downstream middleware component");
|
||||
LogExceptionAndTransition(context, e);
|
||||
FaultAncestors(context);
|
||||
context.Fault(e);
|
||||
await HandleIncidentAsync(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogExceptionAndTransition(ActivityExecutionContext context, Exception e)
|
||||
{
|
||||
context.Exception = e;
|
||||
context.TransitionTo(ActivityStatus.Faulted);
|
||||
var activity = context.Activity;
|
||||
var exceptionState = ExceptionState.FromException(e);
|
||||
var now = systemClock.UtcNow;
|
||||
var incident = new ActivityIncident(activity.Id, activity.NodeId ,activity.Type, e.Message, exceptionState, now);
|
||||
context.WorkflowExecutionContext.Incidents.Add(incident);
|
||||
}
|
||||
|
||||
private async Task HandleIncidentAsync(ActivityExecutionContext context)
|
||||
{
|
||||
var strategy = await incidentStrategyResolver.ResolveStrategyAsync(context);
|
||||
strategy.HandleIncident(context);
|
||||
}
|
||||
|
||||
private static void FaultAncestors(ActivityExecutionContext context)
|
||||
{
|
||||
var ancestors = context.GetAncestors();
|
||||
|
||||
foreach (var ancestor in ancestors)
|
||||
ancestor.TransitionTo(ActivityStatus.Faulted);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,33 @@ namespace Elsa.Workflows.Models;
|
|||
/// </summary>
|
||||
public class ActivityHandle
|
||||
{
|
||||
public static ActivityHandle FromActivityId(string activityId) => new() { ActivityId = activityId };
|
||||
public static ActivityHandle FromActivityNodeId(string activityNodeId) => new() { ActivityNodeId = activityNodeId };
|
||||
public static ActivityHandle FromActivityInstanceId(string activityInstanceId) => new() { ActivityInstanceId = activityInstanceId };
|
||||
public static ActivityHandle FromActivityHash(string activityHash) => new() { ActivityHash = activityHash };
|
||||
public static ActivityHandle FromActivityId(string activityId) => new()
|
||||
{
|
||||
ActivityId = activityId
|
||||
};
|
||||
|
||||
public static ActivityHandle FromActivityNodeId(string activityNodeId) => new()
|
||||
{
|
||||
ActivityNodeId = activityNodeId
|
||||
};
|
||||
|
||||
public static ActivityHandle FromActivityInstanceId(string activityInstanceId) => new()
|
||||
{
|
||||
ActivityInstanceId = activityInstanceId
|
||||
};
|
||||
|
||||
public static ActivityHandle FromActivityHash(string activityHash) => new()
|
||||
{
|
||||
ActivityHash = activityHash
|
||||
};
|
||||
|
||||
public string? ActivityId { get; init; }
|
||||
public string? ActivityNodeId { get; init;}
|
||||
public string? ActivityInstanceId { get; init;}
|
||||
public string? ActivityHash { get; init;}
|
||||
public string? ActivityNodeId { get; init; }
|
||||
public string? ActivityInstanceId { get; init; }
|
||||
public string? ActivityHash { get; init; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ActivityId ?? (ActivityNodeId ?? (ActivityInstanceId ?? (ActivityHash ?? "")));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue