Add tenant headers support to BackgroundWorkflowCancellationDispatcher (#7040)
* Add tenant headers support to BackgroundWorkflowCancellationDispatcher * Fix 'CreateHeaders' call
This commit is contained in:
parent
ffd4327d2a
commit
bc70beff12
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue