elsa-core/src/modules/Elsa.Http/Handlers/UpdateRouteTable.cs
Sipke Schoorstra c8d87cd763
Simplify Proto.Actor bookmarks and triggers (#3917)
* Refactor HTTP route table population

* Update workflow definition EF store to use abstract IWorkflowInstanceStore

This decoupling is necessary, because the application might not be using EF Core, but e.g. Elasticsearch

* Move workflow state persistence to the default workflow runtime feature

* Update JS handler to provide access to variables during trigger indexing

* Configure Proto.Actor runtime with different workflow pipeline

* Add sample using Proto.Actor runtime

* Replace BookmarkGrain with DB based persistence
2023-04-17 15:23:05 +02:00

38 lines
1.4 KiB
C#

using Elsa.Extensions;
using Elsa.Http.Contracts;
using Elsa.Mediator.Contracts;
using Elsa.Workflows.Runtime.Notifications;
namespace Elsa.Http.Handlers;
/// <summary>
/// A handler that updates the route table when workflow triggers and bookmarks are indexed.
/// </summary>
public class UpdateRouteTable :
INotificationHandler<WorkflowTriggersIndexed>,
INotificationHandler<WorkflowBookmarksIndexed>
{
private readonly IRouteTable _routeTable;
/// <summary>
/// Initializes a new instance of the <see cref="UpdateRouteTable"/> class.
/// </summary>
public UpdateRouteTable(IRouteTable routeTable) => _routeTable = routeTable;
/// <inheritdoc />
public Task HandleAsync(WorkflowTriggersIndexed notification, CancellationToken cancellationToken)
{
_routeTable.RemoveRoutes(notification.IndexedWorkflowTriggers.RemovedTriggers);
_routeTable.AddRoutes(notification.IndexedWorkflowTriggers.AddedTriggers);
_routeTable.AddRoutes(notification.IndexedWorkflowTriggers.UnchangedTriggers);
return Task.CompletedTask;
}
/// <inheritdoc />
public Task HandleAsync(WorkflowBookmarksIndexed notification, CancellationToken cancellationToken)
{
_routeTable.RemoveRoutes(notification.IndexedWorkflowBookmarks.RemovedBookmarks);
_routeTable.AddRoutes(notification.IndexedWorkflowBookmarks.AddedBookmarks);
return Task.CompletedTask;
}
}