Changed behaviour on publishing workflows (#5208)
Instead of repopulation the entire ActivityRegistry, only add the new workflow definition.
This commit is contained in:
parent
dea40131b6
commit
702520a5a0
|
|
@ -59,7 +59,12 @@ services
|
|||
.UseWorkflowRuntime(runtime =>
|
||||
{
|
||||
runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
|
||||
runtime.UseMassTransitDispatcher();
|
||||
|
||||
if (useMassTransit)
|
||||
{
|
||||
runtime.UseMassTransitDispatcher();
|
||||
}
|
||||
|
||||
if (useProtoActor)
|
||||
{
|
||||
runtime.UseProtoActor(proto => proto.PersistenceProvider = _ =>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ public class WorkflowDefinitionEventsConsumer(IActivityRegistryPopulator activit
|
|||
public Task Consume(ConsumeContext<WorkflowDefinitionDeleted> context) => RefreshAsync();
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task Consume(ConsumeContext<WorkflowDefinitionPublished> context) => RefreshAsync();
|
||||
public async Task Consume(ConsumeContext<WorkflowDefinitionPublished> context)
|
||||
{
|
||||
await activityRegistryPopulator.AddToRegistry(typeof(WorkflowDefinitionActivityProvider), context.Message.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task Consume(ConsumeContext<WorkflowDefinitionRetracted> context) => RefreshAsync();
|
||||
|
|
|
|||
|
|
@ -19,4 +19,12 @@ public interface IActivityRegistryPopulator
|
|||
/// <param name="providerType">The type of the provider.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
Task PopulateRegistryAsync(Type providerType, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to add a workflow as an activity to the registry.
|
||||
/// </summary>
|
||||
/// <param name="providerType">The type of the activity provider.</param>
|
||||
/// <param name="workflowDefinitionId">The ID of the workflow definition.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
Task AddToRegistry(Type providerType, string workflowDefinitionId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
|
@ -22,7 +22,10 @@ public class RefreshActivityRegistryHandler(IActivityRegistryPopulator activityR
|
|||
INotificationHandler<WorkflowDefinitionVersionsDeleted>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task HandleAsync(WorkflowDefinitionPublished notification, CancellationToken cancellationToken) => await RefreshAsync(cancellationToken);
|
||||
public async Task HandleAsync(WorkflowDefinitionPublished notification, CancellationToken cancellationToken)
|
||||
{
|
||||
await activityRegistryPopulator.AddToRegistry(typeof(WorkflowDefinitionActivityProvider), notification.WorkflowDefinition.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task HandleAsync(WorkflowDefinitionRetracted notification, CancellationToken cancellationToken) => await RefreshAsync(cancellationToken);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,18 @@ public class ActivityRegistryPopulator : IActivityRegistryPopulator
|
|||
await PopulateRegistryAsync(provider, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AddToRegistry(Type providerType, string workflowDefinitionVersionId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var provider = _providers.First(x => x.GetType() == providerType);
|
||||
var descriptors = await provider.GetDescriptorsAsync(cancellationToken);
|
||||
var descriptorToAdd = descriptors
|
||||
.SingleOrDefault(d => d.CustomProperties.TryGetValue("WorkflowDefinitionVersionId", out var val) && val.ToString() == workflowDefinitionVersionId);
|
||||
|
||||
if (descriptorToAdd is not null)
|
||||
_registry.Add(providerType, descriptorToAdd!);
|
||||
}
|
||||
|
||||
private async Task PopulateRegistryAsync(IActivityProvider provider, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var descriptors = await provider.GetDescriptorsAsync(cancellationToken);
|
||||
|
|
|
|||
Loading…
Reference in a new issue