forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for synchronous broadcast in WorkflowInbox
This update introduces a new option to control synchronicity when broadcasting messages in the WorkflowInbox. The 'BroadcastWorkflowInboxMessageOptions' class allows the developer to specify whether the broadcasting will occur synchronously or asynchronously. The update also includes a new Endpoint and Workflow for demonstration and testing of this functionality.
- Loading branch information
1 parent
53bd1f9
commit 652a617
Showing
10 changed files
with
159 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Elsa.Abstractions; | ||
using Elsa.Workflows.Runtime.Contracts; | ||
|
||
namespace Elsa.Server.Web; | ||
|
||
public class MyEndpoint : ElsaEndpointWithoutRequest | ||
{ | ||
private readonly IEventPublisher _eventPublisher; | ||
|
||
public MyEndpoint(IEventPublisher eventPublisher) | ||
{ | ||
_eventPublisher = eventPublisher; | ||
} | ||
|
||
public override void Configure() | ||
{ | ||
Get("/my-event-workflow"); | ||
AllowAnonymous(); | ||
} | ||
|
||
public override async Task HandleAsync(CancellationToken ct) | ||
{ | ||
Console.WriteLine("Publishing MyEvent"); | ||
var results = await _eventPublisher.PublishAsync("MyEvent", cancellationToken: ct); | ||
Console.WriteLine($"Affected workflows: {results.Count}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Elsa.Workflows; | ||
using Elsa.Workflows.Activities; | ||
using Elsa.Workflows.Contracts; | ||
using Elsa.Workflows.Runtime.Activities; | ||
|
||
namespace Elsa.Server.Web; | ||
|
||
public class OnMyEventWorkflow : WorkflowBase | ||
{ | ||
protected override void Build(IWorkflowBuilder builder) | ||
{ | ||
builder.Version = 1; | ||
builder.Id = "OnMyEventWorkflow"; | ||
builder.Root = new Sequence | ||
{ | ||
Activities = | ||
{ | ||
new Event("MyEvent") | ||
{ | ||
CanStartWorkflow = true | ||
}, | ||
new Inline(async () => | ||
{ | ||
// IEventPublisher.PublishAsync returns before this executes | ||
await SomeCallAsync(); | ||
}), | ||
new WriteLine("End of workflow"), | ||
new Finish() | ||
} | ||
}; | ||
} | ||
|
||
private async Task SomeCallAsync() | ||
{ | ||
Console.WriteLine("Hello from OnMyEventWorkflow"); | ||
await Task.Delay(1000); | ||
Console.WriteLine("Goodbye from OnMyEventWorkflow"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/modules/Elsa.Workflows.Runtime/Models/BroadcastWorkflowInboxMessageOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Elsa.Workflows.Runtime.Models; | ||
|
||
/// <summary> | ||
/// Represents the options for broadcasting a workflow inbox message. | ||
/// </summary> | ||
public class BroadcastWorkflowInboxMessageOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether the dispatch should be executed asynchronously. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if the dispatch should be executed asynchronously; otherwise, <c>false</c>. | ||
/// </value> | ||
public bool DispatchAsynchronously { get; set; } = true; | ||
} |
7 changes: 6 additions & 1 deletion
7
src/modules/Elsa.Workflows.Runtime/Notifications/WorkflowInboxMessageReceived.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
using Elsa.Mediator.Contracts; | ||
using Elsa.Workflows.Runtime.Entities; | ||
using Elsa.Workflows.Runtime.Options; | ||
using Elsa.Workflows.Runtime.Results; | ||
|
||
namespace Elsa.Workflows.Runtime.Notifications; | ||
|
||
/// <summary> | ||
/// A notification that is sent when a workflow inbox message is received. | ||
/// </summary> | ||
/// <param name="InboxMessage">The inbox message that was received.</param> | ||
public record WorkflowInboxMessageReceived(WorkflowInboxMessage InboxMessage) : INotification; | ||
public record WorkflowInboxMessageReceived( | ||
WorkflowInboxMessage InboxMessage, | ||
WorkflowInboxMessageDeliveryOptions Options, | ||
ICollection<WorkflowExecutionResult> WorkflowExecutionResults) : INotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters