2024-10-14 19:27:11 +00:00
|
|
|
|
using Elsa.Http.Options;
|
2023-03-03 21:47:23 +00:00
|
|
|
|
using Elsa.Mediator.Contracts;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
using Elsa.Workflows.Runtime.Notifications;
|
2024-10-14 19:27:11 +00:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2022-04-27 20:32:40 +00:00
|
|
|
|
|
2022-11-19 21:30:43 +00:00
|
|
|
|
namespace Elsa.Http.Handlers;
|
|
|
|
|
|
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <summary>
|
2023-04-17 13:23:05 +00:00
|
|
|
|
/// A handler that updates the route table when workflow triggers and bookmarks are indexed.
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// </summary>
|
2024-10-14 19:27:11 +00:00
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
|
public class UpdateRouteTable(IRouteTableUpdater routeTableUpdater, IOptions<HttpActivityOptions> options) :
|
2022-11-19 21:30:43 +00:00
|
|
|
|
INotificationHandler<WorkflowTriggersIndexed>,
|
|
|
|
|
|
INotificationHandler<WorkflowBookmarksIndexed>
|
2022-04-27 20:32:40 +00:00
|
|
|
|
{
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <inheritdoc />
|
2024-10-14 19:27:11 +00:00
|
|
|
|
public async Task HandleAsync(WorkflowTriggersIndexed notification, CancellationToken cancellationToken)
|
2022-11-19 21:30:43 +00:00
|
|
|
|
{
|
2024-10-14 19:27:11 +00:00
|
|
|
|
routeTableUpdater.RemoveRoutes(notification.IndexedWorkflowTriggers.RemovedTriggers);
|
|
|
|
|
|
await routeTableUpdater.AddRoutesAsync(notification.IndexedWorkflowTriggers.AddedTriggers, cancellationToken);
|
|
|
|
|
|
await routeTableUpdater.AddRoutesAsync(notification.IndexedWorkflowTriggers.UnchangedTriggers, cancellationToken);
|
2022-11-19 21:30:43 +00:00
|
|
|
|
}
|
2022-04-27 20:32:40 +00:00
|
|
|
|
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <inheritdoc />
|
2024-10-14 19:27:11 +00:00
|
|
|
|
public async Task HandleAsync(WorkflowBookmarksIndexed notification, CancellationToken cancellationToken)
|
2022-11-19 21:30:43 +00:00
|
|
|
|
{
|
2024-10-14 19:27:11 +00:00
|
|
|
|
routeTableUpdater.RemoveRoutes(notification.IndexedWorkflowBookmarks.RemovedBookmarks);
|
|
|
|
|
|
await routeTableUpdater.AddRoutesAsync(notification.IndexedWorkflowBookmarks.AddedBookmarks, notification.IndexedWorkflowBookmarks.WorkflowExecutionContext, cancellationToken);
|
2022-04-27 20:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|