Remove redundant Trigger parameter from workflow selection
This commit is contained in:
parent
0850f0ac48
commit
cbfb21c4c9
|
|
@ -72,8 +72,7 @@ namespace Elsa.Activities.AzureServiceBus.Services
|
|||
};
|
||||
|
||||
var bookmark = CreateBookmark(message);
|
||||
var trigger = CreateTrigger(message);
|
||||
var launchContext = new CollectWorkflowsContext(ActivityType, bookmark, trigger, correlationId);
|
||||
var launchContext = new CollectWorkflowsContext(ActivityType, bookmark, correlationId);
|
||||
|
||||
await _workflowLaunchpad.UseServiceAsync(service => service.CollectAndDispatchWorkflowsAsync(launchContext, model, cancellationToken));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ namespace Elsa.Activities.Conductor.Endpoints.Conductor.Events
|
|||
public async Task<IActionResult> Handle(string eventName, EventModel model)
|
||||
{
|
||||
var bookmark = new EventBookmark(eventName.ToLowerInvariant());
|
||||
var trigger = new EventBookmark(eventName.ToLowerInvariant());
|
||||
var context = new CollectWorkflowsContext(nameof(EventReceived), bookmark, trigger, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var context = new CollectWorkflowsContext(nameof(EventReceived), bookmark, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var pendingWorkflows = await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(context, model);
|
||||
|
||||
return Accepted(pendingWorkflows);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ namespace Elsa.Activities.Conductor.Endpoints.Conductor.Events
|
|||
public async Task<IActionResult> Handle(string eventName, EventModel model)
|
||||
{
|
||||
var bookmark = new EventBookmark(eventName);
|
||||
var trigger = new EventBookmark(eventName);
|
||||
var context = new CollectWorkflowsContext(nameof(EventReceived), bookmark, trigger, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var context = new CollectWorkflowsContext(nameof(EventReceived), bookmark, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var pendingWorkflows = await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(context, model);
|
||||
|
||||
return Accepted(pendingWorkflows);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ namespace Elsa.Activities.Conductor.Endpoints.Conductor.Tasks
|
|||
public async Task<IActionResult> Handle(string taskName, TaskResultModel model)
|
||||
{
|
||||
var bookmark = new TaskBookmark(taskName.ToLowerInvariant());
|
||||
var trigger = new TaskBookmark(taskName.ToLowerInvariant());
|
||||
var context = new CollectWorkflowsContext(nameof(RunTask), bookmark, trigger, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var context = new CollectWorkflowsContext(nameof(RunTask), bookmark, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var pendingWorkflows = await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(context, model);
|
||||
|
||||
return Accepted(pendingWorkflows);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ namespace Elsa.Activities.Conductor.Endpoints.Conductor.Tasks
|
|||
public async Task<IActionResult> Handle(string taskName, TaskResultModel model)
|
||||
{
|
||||
var bookmark = new TaskBookmark(taskName.ToLowerInvariant());
|
||||
var trigger = new TaskBookmark(taskName.ToLowerInvariant());
|
||||
var context = new CollectWorkflowsContext(nameof(RunTask), bookmark, trigger, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var context = new CollectWorkflowsContext(nameof(RunTask), bookmark, model.CorrelationId, model.WorkflowInstanceId);
|
||||
var pendingWorkflows = await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(context, model);
|
||||
|
||||
return Accepted(pendingWorkflows);
|
||||
|
|
|
|||
|
|
@ -7,18 +7,16 @@ namespace Elsa.Activities.Entity.Bookmarks
|
|||
{
|
||||
public class EntityChangedBookmark : IBookmark
|
||||
{
|
||||
public EntityChangedBookmark(string? entityName, EntityChangedAction? action, string? contextId, string? correlationId)
|
||||
public EntityChangedBookmark(string? entityName, EntityChangedAction? action, string? contextId)
|
||||
{
|
||||
EntityName = entityName;
|
||||
Action = action;
|
||||
ContextId = contextId;
|
||||
CorrelationId = correlationId;
|
||||
}
|
||||
|
||||
public string? EntityName { get; }
|
||||
public EntityChangedAction? Action { get; }
|
||||
public string? ContextId { get; }
|
||||
public string? CorrelationId { get; }
|
||||
}
|
||||
|
||||
public class EntityChangedWorkflowTriggerProvider : BookmarkProvider<EntityChangedBookmark, EntityChanged>
|
||||
|
|
@ -27,10 +25,9 @@ namespace Elsa.Activities.Entity.Bookmarks
|
|||
new[]
|
||||
{
|
||||
Result(new EntityChangedBookmark(
|
||||
entityName: await context.ReadActivityPropertyAsync(x => x.EntityName, cancellationToken),
|
||||
action: await context.ReadActivityPropertyAsync(x => x.Action, cancellationToken),
|
||||
contextId: context.ActivityExecutionContext.WorkflowExecutionContext.WorkflowInstance.ContextId,
|
||||
correlationId: context.ActivityExecutionContext.WorkflowExecutionContext.WorkflowInstance.CorrelationId
|
||||
await context.ReadActivityPropertyAsync(x => x.EntityName, cancellationToken),
|
||||
await context.ReadActivityPropertyAsync(x => x.Action, cancellationToken),
|
||||
context.ActivityExecutionContext.WorkflowExecutionContext.WorkflowInstance.ContextId
|
||||
))
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Elsa.Activities.Entity.Extensions
|
|||
{
|
||||
public static class WorkflowRunnerExtensions
|
||||
{
|
||||
// TODO: Design multi-tenancy
|
||||
// TODO: Design multi-tenancy.
|
||||
private const string? TenantId = default;
|
||||
|
||||
public static async Task TriggerEntityChangedWorkflowsAsync(
|
||||
|
|
@ -23,21 +23,13 @@ namespace Elsa.Activities.Entity.Extensions
|
|||
const string activityType = nameof(EntityChanged);
|
||||
var input = new EntityChangedContext(entityId, entityName, changedAction);
|
||||
|
||||
var trigger = new EntityChangedBookmark(
|
||||
entityName,
|
||||
changedAction,
|
||||
contextId,
|
||||
null
|
||||
);
|
||||
|
||||
var bookmark = new EntityChangedBookmark(
|
||||
entityName,
|
||||
changedAction,
|
||||
contextId,
|
||||
correlationId
|
||||
contextId
|
||||
);
|
||||
|
||||
await workflowDispatcher.DispatchAsync(new TriggerWorkflowsRequest(activityType, bookmark, trigger, input, correlationId, default, contextId, TenantId), cancellationToken);
|
||||
await workflowDispatcher.DispatchAsync(new TriggerWorkflowsRequest(activityType, bookmark, input, correlationId, default, contextId, TenantId), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +41,8 @@ namespace Elsa.Activities.Http.Middleware
|
|||
request.TryGetCorrelationId(out var correlationId);
|
||||
|
||||
const string activityType = nameof(HttpEndpoint);
|
||||
var trigger = new HttpEndpointBookmark(path, method);
|
||||
var bookmark = new HttpEndpointBookmark(path, method);
|
||||
var collectWorkflowsContext = new CollectWorkflowsContext(activityType, bookmark, trigger, correlationId, default, default, TenantId);
|
||||
var collectWorkflowsContext = new CollectWorkflowsContext(activityType, bookmark, correlationId, default, default, TenantId);
|
||||
var pendingWorkflows = await workflowLaunchpad.CollectWorkflowsAsync(collectWorkflowsContext, cancellationToken).ToList();
|
||||
|
||||
if (!pendingWorkflows.Any())
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ namespace Elsa.Activities.MassTransit.Bookmarks
|
|||
public class MessageReceivedBookmark : IBookmark
|
||||
{
|
||||
public string MessageType { get; set; } = default!;
|
||||
public string? CorrelationId { get; set; }
|
||||
}
|
||||
|
||||
public class MessageReceivedTriggerProvider : BookmarkProvider<MessageReceivedBookmark, ReceiveMassTransitMessage>
|
||||
|
|
@ -18,8 +17,7 @@ namespace Elsa.Activities.MassTransit.Bookmarks
|
|||
{
|
||||
Result(new MessageReceivedBookmark
|
||||
{
|
||||
MessageType = (await context.ReadActivityPropertyAsync(x => x.MessageType, cancellationToken))!.Name,
|
||||
CorrelationId = context.ActivityExecutionContext.WorkflowExecutionContext.CorrelationId
|
||||
MessageType = (await context.ReadActivityPropertyAsync(x => x.MessageType, cancellationToken))!.Name
|
||||
})
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,6 @@ namespace Elsa.Activities.MassTransit.Consumers
|
|||
break;
|
||||
|
||||
var bookmark = new MessageReceivedBookmark
|
||||
{
|
||||
MessageType = message.GetType().Name,
|
||||
CorrelationId = correlationId.ToString()
|
||||
};
|
||||
var trigger = new MessageReceivedBookmark
|
||||
{
|
||||
MessageType = message.GetType().Name
|
||||
};
|
||||
|
|
@ -51,7 +46,6 @@ namespace Elsa.Activities.MassTransit.Consumers
|
|||
await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
|
||||
nameof(ReceiveMassTransitMessage),
|
||||
bookmark,
|
||||
trigger,
|
||||
correlationId.ToString()
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ namespace Elsa.Activities.Rebus.Bookmarks
|
|||
public class MessageReceivedBookmark : IBookmark
|
||||
{
|
||||
public string MessageType { get; set; } = default!;
|
||||
public string? CorrelationId { get; set; }
|
||||
}
|
||||
|
||||
public class MessageReceivedTriggerProvider : BookmarkProvider<MessageReceivedBookmark, RebusMessageReceived>
|
||||
|
|
@ -18,8 +17,7 @@ namespace Elsa.Activities.Rebus.Bookmarks
|
|||
{
|
||||
Result(new MessageReceivedBookmark
|
||||
{
|
||||
MessageType = (await context.ReadActivityPropertyAsync(x => x.MessageType, cancellationToken))!.Name,
|
||||
CorrelationId = context.ActivityExecutionContext.WorkflowExecutionContext.CorrelationId
|
||||
MessageType = (await context.ReadActivityPropertyAsync(x => x.MessageType, cancellationToken))!.Name
|
||||
})
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ namespace Elsa.Activities.Rebus.Consumers
|
|||
var correlationId = MessageContext.Current.TransportMessage.Headers.GetValueOrNull(Headers.CorrelationId);
|
||||
await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
|
||||
nameof(RebusMessageReceived),
|
||||
new MessageReceivedBookmark { MessageType = message.GetType().Name, CorrelationId = correlationId },
|
||||
new MessageReceivedBookmark { MessageType = message.GetType().Name },
|
||||
correlationId,
|
||||
default,
|
||||
|
|
|
|||
|
|
@ -39,9 +39,8 @@ namespace Elsa.Activities.Telnyx.Handlers
|
|||
return;
|
||||
|
||||
var correlationId = GetCorrelationId(receivedPayload);
|
||||
var trigger = CreateBookmark();
|
||||
var bookmark = CreateBookmark();
|
||||
var context = new CollectWorkflowsContext(ActivityTypeName, bookmark, trigger, correlationId);
|
||||
var context = new CollectWorkflowsContext(ActivityTypeName, bookmark, correlationId);
|
||||
await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(context, receivedPayload, cancellationToken);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ namespace Elsa.Activities.Telnyx.Webhooks.Handlers
|
|||
|
||||
var correlationId = GetCorrelationId(payload);
|
||||
var bookmark = new NotificationBookmark(eventType);
|
||||
var trigger = new NotificationBookmark(eventType);
|
||||
var context = new CollectWorkflowsContext(activityType, bookmark, trigger, correlationId);
|
||||
var context = new CollectWorkflowsContext(activityType, bookmark, correlationId);
|
||||
|
||||
await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(context, webhook, cancellationToken);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Elsa.Services
|
||||
{
|
||||
public record TriggerWorkflowsRequest(string ActivityType, IBookmark Bookmark, IBookmark Trigger, object? Input = default, string? CorrelationId = default, string? WorkflowInstanceId = default, string? ContextId = default, string? TenantId = default);
|
||||
public record TriggerWorkflowsRequest(string ActivityType, IBookmark Bookmark, object? Input = default, string? CorrelationId = default, string? WorkflowInstanceId = default, string? ContextId = default, string? TenantId = default);
|
||||
|
||||
public record ExecuteWorkflowDefinitionRequest(string WorkflowDefinitionId, string? ActivityId = default, object? Input = default, string? CorrelationId = default, string? ContextId = default, string? TenantId = default);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ namespace Elsa.Services
|
|||
Task<IEnumerable<CollectedWorkflow>> CollectAndDispatchWorkflowsAsync(CollectWorkflowsContext context, object? input = default, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public record CollectWorkflowsContext(string ActivityType, IBookmark? Bookmark, IBookmark? Trigger = default, string? CorrelationId = default, string? WorkflowInstanceId = default, string? ContextId = default, string? TenantId = default);
|
||||
public record CollectWorkflowsContext(string ActivityType, IBookmark? Bookmark, string? CorrelationId = default, string? WorkflowInstanceId = default, string? ContextId = default, string? TenantId = default);
|
||||
|
||||
public record CollectStartableWorkflowsContext(string WorkflowDefinitionId, string? ActivityId = default, string? CorrelationId = default, string? ContextId = default, string? TenantId = default);
|
||||
}
|
||||
|
|
@ -37,7 +37,6 @@ namespace Elsa.Activities.Signaling.Services
|
|||
return await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
|
||||
nameof(SignalReceived),
|
||||
new SignalReceivedBookmark { Signal = normalizedSignal },
|
||||
new SignalReceivedBookmark { Signal = normalizedSignal },
|
||||
correlationId,
|
||||
workflowInstanceId,
|
||||
default,
|
||||
|
|
@ -53,17 +52,20 @@ namespace Elsa.Activities.Signaling.Services
|
|||
return await DispatchSignalAsync(signal.Name, input, signal.WorkflowInstanceId, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CollectedWorkflow>> DispatchSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, string? correlationId = default, CancellationToken cancellationToken = default) =>
|
||||
await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(new CollectWorkflowsContext(
|
||||
nameof(SignalReceived),
|
||||
new SignalReceivedBookmark { Signal = signal },
|
||||
new SignalReceivedBookmark { Signal = signal },
|
||||
correlationId,
|
||||
workflowInstanceId,
|
||||
default,
|
||||
TenantId
|
||||
),
|
||||
new Signal(signal, input),
|
||||
cancellationToken);
|
||||
public async Task<IEnumerable<CollectedWorkflow>> DispatchSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, string? correlationId = default, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var normalizedSignal = signal.ToLowerInvariant();
|
||||
|
||||
return await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(new CollectWorkflowsContext(
|
||||
nameof(SignalReceived),
|
||||
new SignalReceivedBookmark { Signal = normalizedSignal },
|
||||
correlationId,
|
||||
workflowInstanceId,
|
||||
default,
|
||||
TenantId
|
||||
),
|
||||
new Signal(normalizedSignal, input),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,8 +16,7 @@ namespace Elsa.Services.Dispatch.Consumers
|
|||
{
|
||||
var pendingWorkflows = await _workflowLaunchpad.CollectWorkflowsAsync(new CollectWorkflowsContext(
|
||||
message.ActivityType,
|
||||
message.Bookmark,
|
||||
message.Trigger,
|
||||
message.Bookmark,
|
||||
message.CorrelationId,
|
||||
message.WorkflowInstanceId,
|
||||
message.ContextId,
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ namespace Elsa.Services.Workflows
|
|||
{
|
||||
_logger.LogDebug("Triggering workflows using {ActivityType}", context.ActivityType);
|
||||
|
||||
var filter = context.Trigger ?? context.Bookmark;
|
||||
var filter = context.Bookmark;
|
||||
var triggers = filter != null ? (await _triggerFinder.FindTriggersAsync(context.ActivityType, filter, context.TenantId, cancellationToken)).ToList() : new List<TriggerFinderResult>();
|
||||
var startableWorkflows = new List<StartableWorkflow>();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Elsa.Server.Api.Endpoints.Workflows
|
|||
public record DispatchTriggerWorkflowsRequestModel(string ActivityType, IBookmark? Bookmark, IBookmark? Trigger, string? CorrelationId, string? WorkflowInstanceId, string? ContextId, object? Input);
|
||||
|
||||
public record DispatchTriggerWorkflowsResponseModel(ICollection<CollectedWorkflow> PendingWorkflows);
|
||||
public record TriggerWorkflowsRequestModel(string ActivityType, IBookmark? Bookmark, IBookmark? Trigger, string? CorrelationId, string? WorkflowInstanceId, string? ContextId, object? Input, bool Dispatch);
|
||||
public record TriggerWorkflowsRequestModel(string ActivityType, IBookmark? Bookmark, string? CorrelationId, string? WorkflowInstanceId, string? ContextId, object? Input, bool Dispatch);
|
||||
|
||||
public record TriggerWorkflowsResponseModel(ICollection<TriggeredWorkflowModel> TriggeredWorkflows);
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ namespace Elsa.Server.Api.Endpoints.Workflows
|
|||
public async Task<IActionResult> Handle(TriggerWorkflowsRequestModel request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken);
|
||||
var context = new CollectWorkflowsContext(request.ActivityType, request.Bookmark, request.Trigger, request.CorrelationId, request.WorkflowInstanceId, request.ContextId, tenantId);
|
||||
var context = new CollectWorkflowsContext(request.ActivityType, request.Bookmark, request.CorrelationId, request.WorkflowInstanceId, request.ContextId, tenantId);
|
||||
ICollection<TriggeredWorkflowModel> triggeredWorkflows;
|
||||
|
||||
if (request.Dispatch)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ namespace Elsa.Server.Hangfire.Jobs
|
|||
public async Task ExecuteAsync(TriggerWorkflowsRequest request, CancellationToken cancellationToken = default) => await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
|
||||
request.ActivityType,
|
||||
request.Bookmark,
|
||||
request.Trigger,
|
||||
request.CorrelationId,
|
||||
request.WorkflowInstanceId,
|
||||
request.ContextId,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ namespace Elsa.Server.Orleans.Grains
|
|||
public async Task ExecutedCorrelatedWorkflowAsync(TriggerWorkflowsRequest request, CancellationToken cancellationToken = default) => await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
|
||||
request.ActivityType,
|
||||
request.Bookmark,
|
||||
request.Trigger,
|
||||
request.CorrelationId,
|
||||
request.WorkflowInstanceId,
|
||||
request.ContextId,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<PackageReference Include="AutoFixture" Version="4.17.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.66" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
|
|
|
|||
Loading…
Reference in a new issue