V3 update routetable on startup (#3780)
* add triggering all indexes to route table * create hostedservice to run population of routetable
This commit is contained in:
parent
6289d86899
commit
7d7e893a62
|
|
@ -20,4 +20,9 @@ public interface ITriggerIndexer
|
|||
/// Indexes triggers of the specified workflow.
|
||||
/// </summary>
|
||||
Task<IndexedWorkflowTriggers> IndexTriggersAsync(Workflow workflow, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Send message of all triggers in the trigger store to populate the routetable on startup
|
||||
/// </summary>
|
||||
Task<IndexedWorkflowTriggers> IndexAllTriggersAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
|
@ -109,7 +109,8 @@ public class WorkflowRuntimeFeature : FeatureBase
|
|||
Module
|
||||
.ConfigureHostedService<RegisterDescriptors>()
|
||||
.ConfigureHostedService<RegisterExpressionSyntaxDescriptors>()
|
||||
.ConfigureHostedService<PopulateWorkflowDefinitionStore>();
|
||||
.ConfigureHostedService<PopulateWorkflowDefinitionStore>()
|
||||
.ConfigureHostedService<PopulateRouteTable>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Apply()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
using Elsa.Workflows.Runtime.Contracts;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Elsa.Workflows.Runtime.HostedServices;
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously updates the routetable from the triggers.
|
||||
/// </summary>
|
||||
public class PopulateRouteTable : IHostedService
|
||||
{
|
||||
private readonly ITriggerIndexer _triggerIndexer;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public PopulateRouteTable(ITriggerIndexer triggerIndexer)
|
||||
{
|
||||
_triggerIndexer = triggerIndexer;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _triggerIndexer.IndexAllTriggersAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
|
|
@ -67,6 +67,27 @@ public class TriggerIndexer : ITriggerIndexer
|
|||
return await IndexTriggersAsync(workflow, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IndexedWorkflowTriggers> IndexAllTriggersAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var emptyTriggerList = new List<StoredTrigger>(0);
|
||||
|
||||
// Get current triggers
|
||||
var filter = new TriggerFilter();
|
||||
var allTriggersTriggers = await _triggerStore.FindManyAsync(filter, cancellationToken);
|
||||
|
||||
|
||||
//workflow definition already deleted so you do not have one
|
||||
var workflow = new Workflow();
|
||||
|
||||
var indexedWorkflow = new IndexedWorkflowTriggers(workflow, allTriggersTriggers.ToList(), emptyTriggerList, emptyTriggerList);
|
||||
|
||||
// Publish event.
|
||||
await _eventPublisher.PublishAsync(new WorkflowTriggersIndexed(indexedWorkflow), cancellationToken);
|
||||
return indexedWorkflow;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IndexedWorkflowTriggers> IndexTriggersAsync(Workflow workflow, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue