Update running workflow counter when deleting workflow instances

This commit is contained in:
Sipke Schoorstra 2023-07-20 13:10:03 +02:00
parent f71e5c89ce
commit bdc7ffae96
2 changed files with 9 additions and 5 deletions

View file

@ -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<WorkflowInstancesDele
async Task INotificationHandler<WorkflowInstancesDeleting>.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);
}
}
}

View file

@ -8,9 +8,9 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkDelete;
[PublicAPI]
internal class BulkDelete : ElsaEndpoint<Request, Response>
{
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<Request, Response>
public override async Task<Response> 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);
}