From bdc7ffae9654a0378ae67ef6f24e855ba7e0db15 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 20 Jul 2023 13:10:03 +0200 Subject: [PATCH] Update running workflow counter when deleting workflow instances --- .../Elsa.ProtoActor/Handlers/StopRunningWorkflows.cs | 8 ++++++-- .../Endpoints/WorkflowInstances/BulkDelete/Endpoint.cs | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/modules/Elsa.ProtoActor/Handlers/StopRunningWorkflows.cs b/src/modules/Elsa.ProtoActor/Handlers/StopRunningWorkflows.cs index 92f8da0b0..3e9a8472e 100644 --- a/src/modules/Elsa.ProtoActor/Handlers/StopRunningWorkflows.cs +++ b/src/modules/Elsa.ProtoActor/Handlers/StopRunningWorkflows.cs @@ -1,5 +1,6 @@ using Elsa.Extensions; using Elsa.Mediator.Contracts; +using Elsa.ProtoActor.Protos; using Elsa.Workflows.Management.Notifications; using JetBrains.Annotations; using Proto.Cluster; @@ -24,10 +25,13 @@ internal class StopRunningWorkflows : INotificationHandler.HandleAsync(WorkflowInstancesDeleting notification, CancellationToken cancellationToken) { + var runningWorkflowsGrainClient = _cluster.GetNamedRunningWorkflowsGrain(); + foreach (var workflowInstanceId in notification.Ids) { - var client = _cluster.GetNamedWorkflowGrain(workflowInstanceId); - await client.Stop(cancellationToken); + var workflowGrainClient = _cluster.GetNamedWorkflowGrain(workflowInstanceId); + await workflowGrainClient.Stop(cancellationToken); + await runningWorkflowsGrainClient.Unregister(new UnregisterRunningWorkflowRequest { InstanceId = workflowInstanceId }, cancellationToken); } } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkDelete/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkDelete/Endpoint.cs index f43f24c78..97363d3d6 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkDelete/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkDelete/Endpoint.cs @@ -8,9 +8,9 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkDelete; [PublicAPI] internal class BulkDelete : ElsaEndpoint { - private readonly IWorkflowInstanceStore _store; + private readonly IWorkflowInstanceManager _store; - public BulkDelete(IWorkflowInstanceStore store) + public BulkDelete(IWorkflowInstanceManager store) { _store = store; } @@ -24,7 +24,7 @@ internal class BulkDelete : ElsaEndpoint public override async Task ExecuteAsync(Request request, CancellationToken cancellationToken) { var filter = new WorkflowInstanceFilter { Ids = request.Ids }; - var count = await _store.DeleteAsync(filter, cancellationToken); + var count = await _store.BulkDeleteAsync(filter, cancellationToken); return new Response(count); }