Update BackgroundStimulusDispatcher.cs

Include tenant headers during command dispatch.
This commit is contained in:
n84ck 2025-07-12 18:40:52 +02:00 committed by GitHub
parent fd5579e551
commit f11b7d5a21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,7 @@
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;
@ -9,13 +11,18 @@ namespace Elsa.Workflows.Runtime;
/// <summary>
/// A simple implementation that queues the specified request for delivering stimuli on a non-durable background worker.
/// </summary>
public class BackgroundStimulusDispatcher(ICommandSender commandSender) : IStimulusDispatcher
public class BackgroundStimulusDispatcher(ICommandSender commandSender, ITenantAccessor tenantAccessor) : IStimulusDispatcher
{
/// <inheritdoc />
public async Task<DispatchStimulusResponse> SendAsync(DispatchStimulusRequest request, CancellationToken cancellationToken = default)
{
var command = new DispatchStimulusCommand(request);
await commandSender.SendAsync(command, CommandStrategy.Background, cancellationToken);
await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
return DispatchStimulusResponse.Empty;
}
}
private IDictionary<object, object> CreateHeaders()
{
return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
}
}