Add tenant headers support to BackgroundWorkflowCancellationDispatcher (#7040)

* Add tenant headers support to BackgroundWorkflowCancellationDispatcher

* Fix 'CreateHeaders' call
This commit is contained in:
Sverre Winkelmans 2026-01-16 15:07:06 +07:00 committed by GitHub
parent ffd4327d2a
commit bc70beff12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,21 +1,28 @@
using Elsa.Mediator;
using Elsa.Mediator.Contracts;
using Elsa.Workflows.Runtime.Commands;
using Elsa.Workflows.Runtime.Requests;
using Elsa.Workflows.Runtime.Responses;
namespace Elsa.Workflows.Runtime;
/// <summary>
/// Dispatches workflow cancellation requests to a local background worker.
/// </summary>
public class BackgroundWorkflowCancellationDispatcher(ICommandSender commandSender) : IWorkflowCancellationDispatcher
{
/// <inheritdoc />
public async Task<DispatchCancelWorkflowsResponse> DispatchAsync(DispatchCancelWorkflowRequest request, CancellationToken cancellationToken = default)
{
var command = new CancelWorkflowsCommand(request);
await commandSender.SendAsync(command, CommandStrategy.Background, cancellationToken);
return new DispatchCancelWorkflowsResponse();
}
using Elsa.Common.Multitenancy;
using Elsa.Mediator;
using Elsa.Mediator.Contracts;
using Elsa.Tenants.Mediator;
using Elsa.Workflows.Runtime.Commands;
using Elsa.Workflows.Runtime.Requests;
using Elsa.Workflows.Runtime.Responses;
namespace Elsa.Workflows.Runtime;
/// <summary>
/// Dispatches workflow cancellation requests to a local background worker.
/// </summary>
public class BackgroundWorkflowCancellationDispatcher(ICommandSender commandSender, ITenantAccessor tenantAccessor) : IWorkflowCancellationDispatcher
{
/// <inheritdoc />
public async Task<DispatchCancelWorkflowsResponse> DispatchAsync(DispatchCancelWorkflowRequest request, CancellationToken cancellationToken = default)
{
var command = new CancelWorkflowsCommand(request);
await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
return new DispatchCancelWorkflowsResponse();
}
private IDictionary<object, object> CreateHeaders()
{
return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
}
}