Merge branch 'v3-token-refresh' into v3
This commit is contained in:
commit
ed0f88ce62
|
|
@ -1,14 +1,9 @@
|
|||
using Elastic.Clients.Elasticsearch;
|
||||
using Elsa.Elasticsearch.Extensions;
|
||||
using Elsa.Elasticsearch.HostedServices;
|
||||
using Elsa.Elasticsearch.Modules.Management;
|
||||
using Elsa.Elasticsearch.Modules.Runtime;
|
||||
using Elsa.Elasticsearch.Options;
|
||||
using Elsa.Elasticsearch.Services;
|
||||
using Elsa.Features.Abstractions;
|
||||
using Elsa.Features.Services;
|
||||
using Elsa.Workflows.Management.Entities;
|
||||
using Elsa.Workflows.Runtime.Entities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
@ -30,12 +25,6 @@ public class ElasticsearchFeature : FeatureBase
|
|||
/// </summary>
|
||||
public Action<ElasticsearchOptions> Options { get; set; } = _ => { };
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ConfigureHostedServices()
|
||||
{
|
||||
Module.ConfigureHostedService<ConfigureAliasesHostedService>(-2);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Apply()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
using Elastic.Clients.Elasticsearch;
|
||||
using Elastic.Clients.Elasticsearch.IndexManagement;
|
||||
using Elsa.Elasticsearch.Options;
|
||||
using Elsa.Elasticsearch.Services;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Elsa.Elasticsearch.HostedServices;
|
||||
|
||||
/// <summary>
|
||||
/// Configures aliases.
|
||||
/// </summary>
|
||||
public class ConfigureAliasesHostedService : IHostedService
|
||||
{
|
||||
private readonly ElasticsearchClient _client;
|
||||
private readonly ElasticsearchOptions _options;
|
||||
private readonly IEnumerable<IIndexConfiguration> _configurations;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public ConfigureAliasesHostedService(ElasticsearchClient client, IOptions<ElasticsearchOptions> options, IEnumerable<IIndexConfiguration> configurations)
|
||||
{
|
||||
_client = client;
|
||||
_options = options.Value;
|
||||
_configurations = configurations;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await ConfigureClientAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
private async Task ConfigureClientAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var configuration in _configurations)
|
||||
await configuration.ConfigureClientAsync(_client, cancellationToken);
|
||||
|
||||
foreach (var configuration in _configurations)
|
||||
{
|
||||
var alias = _options.GetIndexNameFor(configuration.DocumentType);
|
||||
var indexName = configuration.IndexNamingStrategy.GenerateName(alias);
|
||||
var indexExists = (await _client.Indices.ExistsAsync(indexName, cancellationToken)).Exists;
|
||||
|
||||
if (indexExists)
|
||||
continue;
|
||||
|
||||
var response = await _client.Indices.CreateAsync(indexName, c => c
|
||||
.Aliases(a => a.Add(alias, new Alias { IsWriteIndex = true })), cancellationToken);
|
||||
|
||||
if (response.IsValidResponse)
|
||||
continue;
|
||||
|
||||
if (response.TryGetOriginalException(out var exception))
|
||||
throw exception!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,6 @@ public class EFCoreWorkflowManagementPersistenceFeature : PersistenceFeatureBase
|
|||
base.Apply();
|
||||
|
||||
AddStore<WorkflowInstance, EFCoreWorkflowInstanceStore>();
|
||||
AddStore<WorkflowInstance, EFCoreWorkflowInstanceStore>();
|
||||
AddStore<WorkflowDefinition, EFCoreWorkflowDefinitionStore>();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using Elsa.Workflows.Runtime.Features;
|
||||
using Elsa.Workflows.Runtime.Implementations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.EntityFrameworkCore.Modules.Runtime;
|
||||
|
||||
|
|
@ -26,13 +24,4 @@ public static class Extensions
|
|||
feature.Module.Configure(configure);
|
||||
return feature;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the workflow runtime to send workflow state to the <see cref="AsyncWorkflowStateExporter"/>.
|
||||
/// </summary>
|
||||
public static WorkflowRuntimeFeature UseAsyncWorkflowStateExporter(this WorkflowRuntimeFeature feature)
|
||||
{
|
||||
feature.WorkflowStateExporter = sp => ActivatorUtilities.CreateInstance<AsyncWorkflowStateExporter>(sp);
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ namespace Elsa.Workflows.Management.Features;
|
|||
[DependsOn(typeof(MediatorFeature))]
|
||||
[DependsOn(typeof(SystemClockFeature))]
|
||||
[DependsOn(typeof(WorkflowsFeature))]
|
||||
[DependsOn(typeof(WorkflowDefinitionsFeature))]
|
||||
public class WorkflowManagementFeature : FeatureBase
|
||||
{
|
||||
private const string PrimitivesCategory = "Primitives";
|
||||
|
|
|
|||
|
|
@ -39,4 +39,10 @@ public static class ModuleExtensions
|
|||
feature.Module.Configure(configure);
|
||||
return feature;
|
||||
}
|
||||
|
||||
public static WorkflowRuntimeFeature UseAsyncWorkflowStateExporter(this WorkflowRuntimeFeature feature, Action<AsyncWorkflowStateExporterFeature>? configure = default)
|
||||
{
|
||||
feature.Module.Configure(configure);
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using Elsa.Features.Abstractions;
|
||||
using Elsa.Features.Attributes;
|
||||
using Elsa.Features.Services;
|
||||
using Elsa.Workflows.Management.Features;
|
||||
using Elsa.Workflows.Runtime.Implementations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.Workflows.Runtime.Features;
|
||||
|
||||
/// <summary>
|
||||
/// Configures and enables <see cref="AsyncWorkflowStateExporter"/>.
|
||||
/// </summary>
|
||||
[DependsOn(typeof(WorkflowInstancesFeature))]
|
||||
public class AsyncWorkflowStateExporterFeature : FeatureBase
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public AsyncWorkflowStateExporterFeature(IModule module) : base(module)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Configure()
|
||||
{
|
||||
Module.Configure<WorkflowRuntimeFeature>(workflowRuntime => workflowRuntime.WorkflowStateExporter = sp => ActivatorUtilities.CreateInstance<AsyncWorkflowStateExporter>(sp));
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ public class WorkflowRuntimeFeature : FeatureBase
|
|||
/// <summary>
|
||||
/// A factory that instantiates an <see cref="IWorkflowStateExporter"/>.
|
||||
/// </summary>
|
||||
public Func<IServiceProvider, IWorkflowStateExporter> WorkflowStateExporter { get; set; } = sp => sp.GetRequiredService<NoopWorkflowStateExporter>();
|
||||
public Func<IServiceProvider, IWorkflowStateExporter> WorkflowStateExporter { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance<NoopWorkflowStateExporter>;
|
||||
|
||||
/// <summary>
|
||||
/// A factory that instantiates an <see cref="ITaskDispatcher"/>.
|
||||
|
|
@ -145,8 +145,6 @@ public class WorkflowRuntimeFeature : FeatureBase
|
|||
.AddWorkflowDefinitionProvider<ClrWorkflowDefinitionProvider>()
|
||||
|
||||
// Workflow state exporter.
|
||||
.AddSingleton<NoopWorkflowStateExporter>()
|
||||
.AddSingleton<AsyncWorkflowStateExporter>()
|
||||
.AddSingleton(WorkflowStateExporter)
|
||||
|
||||
// Domain handlers.
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ services
|
|||
runtime.UseDefaultRuntime(dr => dr.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)));
|
||||
runtime.UseExecutionLogRecords(d => d.UseEntityFrameworkCore(ef => ef.UseSqlite()));
|
||||
runtime.UseExecutionLogRecords(e => e.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)));
|
||||
runtime.WorkflowStateExporter = sp => sp.GetRequiredService<AsyncWorkflowStateExporter>();
|
||||
runtime.UseAsyncWorkflowStateExporter();
|
||||
})
|
||||
.UseActivityDefinitions(feature => feature.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
||||
.UseJobs(jobs => jobs.ConfigureOptions = options => options.WorkerCount = 10)
|
||||
|
|
|
|||
Loading…
Reference in a new issue