Fix that workflows blocked on a signal could not be resumed with just correlation ID

This commit is contained in:
Sipke Schoorstra 2021-07-12 19:24:51 +02:00
parent 5d74899d74
commit 0850f0ac48
5 changed files with 9 additions and 43 deletions

View file

@ -23,9 +23,6 @@ namespace Elsa.Activities.Signaling
[ActivityInput(Hint = "The name of the signal to wait for.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
public string Signal { get; set; } = default!;
[ActivityInput(Hint = "The scope of the signal to wait for.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid }, DefaultValue = SignalScope.Instance, Category = PropertyCategories.Advanced)]
public SignalScope Scope { get; set; } = SignalScope.Instance;
[ActivityOutput(Hint = "The input that was received with the signal.")]
public object? SignalInput { get; set; }

View file

@ -11,7 +11,6 @@ namespace Elsa.Activities.Signaling
public class SignalReceivedBookmark : IBookmark
{
public string Signal { get; set; } = default!;
public string? WorkflowInstanceId { get; set; }
}
public class SignalReceivedBookmarkProvider : BookmarkProvider<SignalReceivedBookmark, SignalReceived>
@ -21,25 +20,11 @@ namespace Elsa.Activities.Signaling
private async IAsyncEnumerable<BookmarkResult> GetBookmarksInternalAsync(BookmarkProviderContext<SignalReceived> context, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var signalName = (await context.ReadActivityPropertyAsync(x => x.Signal, cancellationToken))!.ToLowerInvariant();
var signalScope = (await context.ReadActivityPropertyAsync(x => x.Scope, cancellationToken))!;
if (context.Mode == BookmarkIndexingMode.WorkflowBlueprint || signalScope == SignalScope.Global)
yield return Result(new SignalReceivedBookmark
{
yield return Result(new SignalReceivedBookmark
{
Signal = signalName
});
yield break;
}
if (signalScope == SignalScope.Instance)
{
yield return Result(new SignalReceivedBookmark
{
Signal = signalName,
WorkflowInstanceId = context.ActivityExecutionContext.WorkflowInstance.Id
});
}
Signal = signalName
});
}
}
}

View file

@ -1,16 +0,0 @@
// ReSharper disable once CheckNamespace
namespace Elsa.Activities.Signaling
{
public enum SignalScope
{
/// <summary>
/// Only signals targeting a specific workflow instance will be handled.
/// </summary>
Instance,
/// <summary>
/// All signals with a specified name will be handled.
/// </summary>
Global
}
}

View file

@ -36,7 +36,7 @@ namespace Elsa.Activities.Signaling.Services
return await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(new CollectWorkflowsContext(
nameof(SignalReceived),
new SignalReceivedBookmark { Signal = normalizedSignal, WorkflowInstanceId = workflowInstanceId },
new SignalReceivedBookmark { Signal = normalizedSignal },
new SignalReceivedBookmark { Signal = normalizedSignal },
correlationId,
workflowInstanceId,
@ -56,7 +56,7 @@ namespace Elsa.Activities.Signaling.Services
public async Task<IEnumerable<CollectedWorkflow>> DispatchSignalAsync(string signal, object? input = default, string? workflowInstanceId = default, string? correlationId = default, CancellationToken cancellationToken = default) =>
await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(new CollectWorkflowsContext(
nameof(SignalReceived),
new SignalReceivedBookmark { Signal = signal, WorkflowInstanceId = workflowInstanceId },
new SignalReceivedBookmark { Signal = signal },
new SignalReceivedBookmark { Signal = signal },
correlationId,
workflowInstanceId,

View file

@ -7,12 +7,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1"/>
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Elsa\Elsa.csproj"/>
<ProjectReference Include="..\..\..\core\Elsa\Elsa.csproj" />
</ItemGroup>
</Project>