Fix signaling
This commit is contained in:
parent
a6d05cfce0
commit
0acc836f4b
|
|
@ -27,7 +27,7 @@ namespace Elsa.Activities.Http.Endpoints.Signals
|
|||
if (!_tokenService.TryDecryptToken(token, out Signal signal))
|
||||
return NotFound();
|
||||
|
||||
await _signaler.DispatchSignalAsync(signal.Name, null, signal.CorrelationId, cancellationToken);
|
||||
await _signaler.DispatchSignalAsync(signal.Name, null, signal.WorkflowInstanceId, cancellationToken);
|
||||
return Accepted();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Elsa.Activities.Http.Endpoints.Signals
|
|||
if (!_tokenService.TryDecryptToken(token, out Signal signal))
|
||||
return NotFound();
|
||||
|
||||
await _signaler.TriggerSignalAsync(signal.Name, null, signal.CorrelationId, cancellationToken);
|
||||
await _signaler.TriggerSignalAsync(signal.Name, null, signal.WorkflowInstanceId, cancellationToken);
|
||||
|
||||
return HttpContext.Items.ContainsKey(WorkflowHttpResult.Instance)
|
||||
? (IActionResult)new EmptyResult()
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ namespace Elsa.Activities.Http.Models
|
|||
{
|
||||
}
|
||||
|
||||
public Signal(string name, string correlationId)
|
||||
public Signal(string name, string workflowInstanceId)
|
||||
{
|
||||
Name = name;
|
||||
CorrelationId = correlationId;
|
||||
WorkflowInstanceId = workflowInstanceId;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = default!;
|
||||
public string CorrelationId { get; set; } = default!;
|
||||
public string WorkflowInstanceId { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ namespace Elsa.Activities.Signaling
|
|||
public class SignalReceivedBookmark : IBookmark
|
||||
{
|
||||
public string Signal { get; set; } = default!;
|
||||
public string? CorrelationId { get; set; }
|
||||
public string? WorkflowInstanceId { get; set; }
|
||||
}
|
||||
|
||||
public class SignalReceivedBookmarkProvider : BookmarkProvider<SignalReceivedBookmark, SignalReceived>
|
||||
|
|
@ -20,7 +20,7 @@ namespace Elsa.Activities.Signaling
|
|||
new SignalReceivedBookmark
|
||||
{
|
||||
Signal = (await context.Activity.GetPropertyValueAsync(x => x.Signal, cancellationToken))!,
|
||||
CorrelationId = context.ActivityExecutionContext.WorkflowExecutionContext.CorrelationId
|
||||
WorkflowInstanceId = context.ActivityExecutionContext.WorkflowInstance.Id
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ namespace Elsa.Activities.Signaling.Services
|
|||
/// <summary>
|
||||
/// Runs all workflows that start with or are blocked on the <see cref="SignalReceived"/> activity.
|
||||
/// </summary>
|
||||
Task TriggerSignalAsync(string signal, object? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
|
||||
Task TriggerSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Dispatches all workflows that start with or are blocked on the <see cref="SignalReceived"/> activity.
|
||||
/// </summary>
|
||||
Task DispatchSignalAsync(string signal, object? input = default, string? correlationId = default, CancellationToken cancellationToken = default);
|
||||
Task DispatchSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,25 +20,23 @@ namespace Elsa.Activities.Signaling.Services
|
|||
_workflowDispatcher = workflowDispatcher;
|
||||
}
|
||||
|
||||
public async Task TriggerSignalAsync(string signal, object? input = default, string? correlationId = default, CancellationToken cancellationToken = default) =>
|
||||
public async Task TriggerSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, CancellationToken cancellationToken = default) =>
|
||||
await _triggersWorkflows.TriggerWorkflowsAsync(
|
||||
nameof(SignalReceived),
|
||||
new SignalReceivedBookmark { Signal = signal, CorrelationId = correlationId },
|
||||
new SignalReceivedBookmark { Signal = signal, WorkflowInstanceId = workflowInstanceId },
|
||||
new SignalReceivedBookmark { Signal = signal },
|
||||
correlationId,
|
||||
default,
|
||||
new Signal(signal, input),
|
||||
tenantId: TenantId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
public async Task DispatchSignalAsync(string signal, object? input = default, string? correlationId = default, CancellationToken cancellationToken = default) =>
|
||||
public async Task DispatchSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, CancellationToken cancellationToken = default) =>
|
||||
await _workflowDispatcher.DispatchAsync(new TriggerWorkflowsRequest(
|
||||
nameof(SignalReceived),
|
||||
new SignalReceivedBookmark { Signal = signal, CorrelationId = correlationId },
|
||||
new SignalReceivedBookmark { Signal = signal, WorkflowInstanceId = workflowInstanceId },
|
||||
new SignalReceivedBookmark { Signal = signal },
|
||||
new Signal(signal, input),
|
||||
correlationId,
|
||||
TenantId: TenantId),
|
||||
new Signal(signal, input)),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,11 +9,11 @@ namespace Elsa.Services
|
|||
/// </summary>
|
||||
public class ActivityExecutionContextForActivityBlueprintFactory : ICreatesActivityExecutionContextForActivityBlueprint
|
||||
{
|
||||
readonly IServiceProvider serviceProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public ActivityExecutionContextForActivityBlueprintFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
|
||||
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -23,11 +23,10 @@ namespace Elsa.Services
|
|||
/// <param name="workflowExecutionContext">A workflow execution context</param>
|
||||
/// <param name="cancellationToken">A cancellation token</param>
|
||||
/// <returns>An activity execution context</returns>
|
||||
public ActivityExecutionContext CreateActivityExecutionContext(IActivityBlueprint activityBlueprint,
|
||||
WorkflowExecutionContext workflowExecutionContext,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return new ActivityExecutionContext(serviceProvider, workflowExecutionContext, activityBlueprint, null, false, cancellationToken);
|
||||
}
|
||||
public ActivityExecutionContext CreateActivityExecutionContext(
|
||||
IActivityBlueprint activityBlueprint,
|
||||
WorkflowExecutionContext workflowExecutionContext,
|
||||
CancellationToken cancellationToken) =>
|
||||
new(_serviceProvider, workflowExecutionContext, activityBlueprint, null, false, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ namespace Elsa.Samples.SignalingConsole
|
|||
// The workflows are now suspended at the red light.
|
||||
// Trigger a green light signal for the first car.
|
||||
var signaler = services.GetRequiredService<ISignaler>();
|
||||
await signaler.TriggerSignalAsync("Green", correlationId: "Car 2");
|
||||
await signaler.TriggerSignalAsync("Green", workflowInstanceId: "Car 2");
|
||||
|
||||
// Notice that only the workflow correlated to the second car executed.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue