From ce2434f9fd897612cae3166f24a450458e968f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrkan=20G=C3=BCran?= Date: Mon, 9 Jan 2023 16:36:58 +0100 Subject: [PATCH] Implemented rollover strategy --- .../Common/ElasticConfiguration.cs | 2 +- .../Common/ElasticFeatureBase.cs | 20 ++++++-- .../Elsa.Elasticsearch/Common/ElasticStore.cs | 20 ++++---- .../Elsa.Elasticsearch/Common/Utils.cs | 26 ++++++++-- .../Elsa.Elasticsearch.csproj | 1 + .../Extensions/ElasticExtensions.cs | 27 +++------- .../ConfigureElasticsearchHostedService.cs | 51 +++++++++++++++++++ .../RolloverOnMonthlyBasis.cs | 35 +++++++++++++ .../Models/IndexRolloverStrategy.cs | 17 +++++++ .../Modules/Management/Extensions.cs | 12 ++++- .../WorkflowInstanceConfiguration.cs | 4 +- .../Runtime/ExecutionLogConfiguration.cs | 4 +- .../Modules/Runtime/Extensions.cs | 12 ++++- .../Options/ElasticsearchOptions.cs | 2 +- .../Scheduling}/ConfigureElasticIndicesJob.cs | 2 +- .../Services/IElasticConfiguration.cs | 6 +-- .../Services/IRolloverStrategy.cs | 6 +++ .../DependencyInjectionExtensions.cs | 1 + .../Features/SchedulingFeature.cs | 1 - .../ElasticCongurationScheduler.cs | 28 ---------- .../Services/IElasticCongurationScheduler.cs | 8 --- .../State/ExceptionState.cs | 4 +- 22 files changed, 201 insertions(+), 88 deletions(-) create mode 100644 src/modules/Elsa.Elasticsearch/HostedServices/ConfigureElasticsearchHostedService.cs create mode 100644 src/modules/Elsa.Elasticsearch/Implementations/RolloverStrategies/RolloverOnMonthlyBasis.cs create mode 100644 src/modules/Elsa.Elasticsearch/Models/IndexRolloverStrategy.cs rename src/modules/{Elsa.Scheduling/Jobs => Elsa.Elasticsearch/Scheduling}/ConfigureElasticIndicesJob.cs (97%) create mode 100644 src/modules/Elsa.Elasticsearch/Services/IRolloverStrategy.cs delete mode 100644 src/modules/Elsa.Scheduling/Implementations/ElasticCongurationScheduler.cs delete mode 100644 src/modules/Elsa.Scheduling/Services/IElasticCongurationScheduler.cs diff --git a/src/modules/Elsa.Elasticsearch/Common/ElasticConfiguration.cs b/src/modules/Elsa.Elasticsearch/Common/ElasticConfiguration.cs index c42110ab8..7f62fd373 100644 --- a/src/modules/Elsa.Elasticsearch/Common/ElasticConfiguration.cs +++ b/src/modules/Elsa.Elasticsearch/Common/ElasticConfiguration.cs @@ -5,5 +5,5 @@ namespace Elsa.Elasticsearch.Common; public abstract class ElasticConfiguration : IElasticConfiguration { - public abstract void Apply(ConnectionSettings connectionSettings, IDictionary aliasConfig); + public abstract void Apply(ConnectionSettings connectionSettings, IDictionary indexConfig); } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Common/ElasticFeatureBase.cs b/src/modules/Elsa.Elasticsearch/Common/ElasticFeatureBase.cs index cfde91c9c..45eb27eab 100644 --- a/src/modules/Elsa.Elasticsearch/Common/ElasticFeatureBase.cs +++ b/src/modules/Elsa.Elasticsearch/Common/ElasticFeatureBase.cs @@ -1,6 +1,9 @@ using Elasticsearch.Net; using Elsa.Elasticsearch.Extensions; +using Elsa.Elasticsearch.HostedServices; +using Elsa.Elasticsearch.Models; using Elsa.Elasticsearch.Options; +using Elsa.Elasticsearch.Scheduling; using Elsa.Elasticsearch.Services; using Elsa.Features.Abstractions; using Elsa.Features.Services; @@ -16,14 +19,25 @@ public abstract class ElasticFeatureBase : FeatureBase } internal ElasticsearchOptions Options { get; set; } = new(); - internal IDictionary AliasConfig { get; set; } = IElasticConfiguration.GetDefaultAliasConfig(); + internal IDictionary IndexConfig { get; set; } = IElasticConfiguration.GetDefaultIndexConfig(); + internal IndexRolloverStrategy? IndexRolloverStrategy { get; set; } + + public override void ConfigureHostedServices() + { + Module.ConfigureHostedService(-1); + } public override void Apply() { if (Services.Any(x => x.ServiceType == typeof(ElasticClient))) return; var elasticClient = new ElasticClient(GetSettings()); - elasticClient.ConfigureIndicesAndAliases(AliasConfig); + + if (IndexRolloverStrategy != null) + { + elasticClient.ApplyRolloverStrategy(IndexConfig, IndexRolloverStrategy!); + } + Services.AddSingleton(elasticClient); } @@ -31,7 +45,7 @@ public abstract class ElasticFeatureBase : FeatureBase { return new ConnectionSettings(new Uri(Options.Endpoint)) .ConfigureAuthentication(Options) - .ConfigureMapping(AliasConfig); + .ConfigureMapping(IndexConfig); } protected void AddStore() where TModel : class where TStore : class diff --git a/src/modules/Elsa.Elasticsearch/Common/ElasticStore.cs b/src/modules/Elsa.Elasticsearch/Common/ElasticStore.cs index 2dc37a24f..0c7b43904 100644 --- a/src/modules/Elsa.Elasticsearch/Common/ElasticStore.cs +++ b/src/modules/Elsa.Elasticsearch/Common/ElasticStore.cs @@ -20,7 +20,7 @@ public class ElasticStore where T : class { var response = await _elasticClient.GetAsync(DocumentPath.Id(id), ct: cancellationToken); - if (response.IsValid) return response.Source; + if (response.ApiCall.Success) return response.Source; _logger.LogError("Failed to fetch data from Elasticsearch: {message}", response.ServerError?.ToString()); return null; @@ -36,7 +36,8 @@ public class ElasticStore where T : class var response = await _elasticClient.SearchAsync(search, cancellationToken); - if (response.IsValid) return new Page(response.Hits.Select(hit => hit.Source).ToList(), response.Total); + if (response.ApiCall.Success) + return new Page(response.Hits.Select(hit => hit.Source).ToList(), response.Total); _logger.LogError("Failed to search data in Elasticsearch: {message}", response.ServerError?.ToString()); return new Page(new Collection(), 0); @@ -51,7 +52,8 @@ public class ElasticStore where T : class var response = await _elasticClient.SearchAsync(search, cancellationToken); - if (response.IsValid) return new Page(response.Hits.Select(hit => hit.Source).ToList(), response.Total); + if (response.ApiCall.Success) + return new Page(response.Hits.Select(hit => hit.Source).ToList(), response.Total); _logger.LogError("Failed to search data in Elasticsearch: {message}", response.ServerError?.ToString()); return new Page(new Collection(), 0); @@ -61,7 +63,7 @@ public class ElasticStore where T : class { var response = await _elasticClient.IndexAsync(model, descriptor => descriptor, cancellationToken); - if (response.IsValid) return true; + if (response.ApiCall.Success) return true; _logger.LogError("Failed to save data in Elasticsearch: {message}", response.ServerError?.ToString()); return false; @@ -71,7 +73,7 @@ public class ElasticStore where T : class { var response = await _elasticClient.IndexManyAsync(documents, cancellationToken: cancellationToken); - if (response.IsValid) return true; + if (response.ApiCall.Success) return true; _logger.LogError("Failed to save data in Elasticsearch: {message}", response.ServerError?.ToString()); return false; @@ -81,7 +83,7 @@ public class ElasticStore where T : class { var response = await _elasticClient.DeleteAsync(DocumentPath.Id(id), ct: cancellationToken); - if (response.IsValid) return true; + if (response.ApiCall.Success) return true; _logger.LogError("Failed to delete data in Elasticsearch: {message}", response.ServerError?.ToString()); return false; @@ -91,7 +93,7 @@ public class ElasticStore where T : class { var response = await _elasticClient.DeleteManyAsync(list, cancellationToken: cancellationToken); - if (response.IsValid) return 0; + if (response.ApiCall.Success) return 0; _logger.LogError("Failed to delete data in Elasticsearch: {message}", response.ServerError?.ToString()); return response.Items.Count; @@ -102,7 +104,7 @@ public class ElasticStore where T : class var response = await _elasticClient.DeleteByQueryAsync(q => q .Query(query), cancellationToken); - if (response.IsValid) return true; + if (response.ApiCall.Success) return true; _logger.LogError("Failed to delete data in Elasticsearch: {message}", response.ServerError?.ToString()); return false; @@ -113,7 +115,7 @@ public class ElasticStore where T : class var response = await _elasticClient.CountAsync(s => s.Query(query), cancellationToken); - if (response.IsValid) return response.Count; + if (response.ApiCall.Success) return response.Count; _logger.LogError("Failed to count data in Elasticsearch: {message}", response.ServerError?.ToString()); return 0; diff --git a/src/modules/Elsa.Elasticsearch/Common/Utils.cs b/src/modules/Elsa.Elasticsearch/Common/Utils.cs index 80683cede..728ff1d24 100644 --- a/src/modules/Elsa.Elasticsearch/Common/Utils.cs +++ b/src/modules/Elsa.Elasticsearch/Common/Utils.cs @@ -6,10 +6,14 @@ public static class Utils { public static string GenerateIndexName(string aliasName) { - var month = DateTime.Now.ToString("MM"); - var year = DateTime.Now.Year; - - return aliasName + "-" + year + "-" + month; + var now = DateTime.Now; + var month = now.ToString("MM"); + var year = now.Year; + var day = now.Day; + var hour = now.Hour; + var minute = now.Minute; + + return aliasName + "-" + year + "-" + month + "-" + day + hour + minute; } public static IEnumerable GetElasticConfigurationTypes() => @@ -22,4 +26,18 @@ public static class Utils public static IEnumerable GetElasticDocumentTypes() => GetElasticConfigurationTypes() .Select(t => t.BaseType!.GenericTypeArguments.First()).ToList(); + + public static IDictionary ResolveAliasConfig( + IDictionary defaultConfig, + IDictionary? option1, + IDictionary? option2) + { + var types = GetElasticDocumentTypes(); + + return option1?.Select(kvp => new KeyValuePair(types.First(t => t.Name == kvp.Key), kvp.Value)) + .ToDictionary(x => x.Key, x => x.Value) ?? + option2?.Select(kvp => new KeyValuePair(types.First(t => t.Name == kvp.Key), kvp.Value)) + .ToDictionary(x => x.Key, x => x.Value) ?? + defaultConfig; + } } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Elsa.Elasticsearch.csproj b/src/modules/Elsa.Elasticsearch/Elsa.Elasticsearch.csproj index dacbc8ca1..698925fa1 100644 --- a/src/modules/Elsa.Elasticsearch/Elsa.Elasticsearch.csproj +++ b/src/modules/Elsa.Elasticsearch/Elsa.Elasticsearch.csproj @@ -13,6 +13,7 @@ + diff --git a/src/modules/Elsa.Elasticsearch/Extensions/ElasticExtensions.cs b/src/modules/Elsa.Elasticsearch/Extensions/ElasticExtensions.cs index a407ea691..c5d220120 100644 --- a/src/modules/Elsa.Elasticsearch/Extensions/ElasticExtensions.cs +++ b/src/modules/Elsa.Elasticsearch/Extensions/ElasticExtensions.cs @@ -1,8 +1,11 @@ using Elasticsearch.Net; using Elsa.Elasticsearch.Common; +using Elsa.Elasticsearch.Implementations.RolloverStrategies; +using Elsa.Elasticsearch.Models; using Elsa.Elasticsearch.Options; using Elsa.Elasticsearch.Services; using Nest; +using Index = Nest.Index; namespace Elsa.Elasticsearch.Extensions; @@ -22,34 +25,20 @@ public static class ElasticExtensions return settings; } - public static ConnectionSettings ConfigureMapping(this ConnectionSettings settings, IDictionary aliasConfig) + public static ConnectionSettings ConfigureMapping(this ConnectionSettings settings, IDictionary indexConfig) { foreach (var config in Utils.GetElasticConfigurationTypes()) { var configInstance = (IElasticConfiguration)Activator.CreateInstance(config)!; - configInstance.Apply(settings, aliasConfig); + configInstance.Apply(settings, indexConfig); } return settings; } - public static void ConfigureIndicesAndAliases(this ElasticClient client, IDictionary aliasConfig) + public static void ApplyRolloverStrategy(this ElasticClient client, IDictionary aliasConfig, IndexRolloverStrategy strategy) { - foreach (var type in Utils.GetElasticDocumentTypes()) - { - var aliasName = aliasConfig[type.Name]; - var indexName = Utils.GenerateIndexName(aliasName); - - var indexExists = client.Indices.Exists(indexName).Exists; - - if (indexExists) continue; - - var response = client.Indices.Create(indexName, s => s - .Aliases(a => a.Alias(aliasName)) - .Map(m => m.AutoMap(type))); - - if (response.IsValid) continue; - throw response.OriginalException; - } + var strategyInstance = (IRolloverStrategy)Activator.CreateInstance(strategy.Value, args: client)!; + strategyInstance.Apply(Utils.GetElasticDocumentTypes(), aliasConfig); } } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/HostedServices/ConfigureElasticsearchHostedService.cs b/src/modules/Elsa.Elasticsearch/HostedServices/ConfigureElasticsearchHostedService.cs new file mode 100644 index 000000000..0afce433b --- /dev/null +++ b/src/modules/Elsa.Elasticsearch/HostedServices/ConfigureElasticsearchHostedService.cs @@ -0,0 +1,51 @@ +using Elsa.Elasticsearch.Scheduling; +using Elsa.Jobs.Schedules; +using Elsa.Jobs.Services; +using Elsa.Workflows.Management.Entities; +using Microsoft.Extensions.Hosting; +using Nest; + +namespace Elsa.Elasticsearch.HostedServices; + +public class ConfigureElasticsearchHostedService : IHostedService +{ + private readonly ElasticClient _elasticClient; + private readonly IJobScheduler _jobScheduler; + + public ConfigureElasticsearchHostedService(ElasticClient elasticClient, IJobScheduler jobScheduler) + { + _elasticClient = elasticClient; + _jobScheduler = jobScheduler; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await FlattenProperties(cancellationToken); + + await ScheduleIndexAndAliasConfiguration(cancellationToken); + } + + private async Task ScheduleIndexAndAliasConfiguration(CancellationToken cancellationToken) + { + var job = new ConfigureElasticIndicesJob(); + var schedule = new CronSchedule + { + // At the start of every month + CronExpression = "*/5 * * * *" + }; + + await _jobScheduler.ScheduleAsync(job, GetType().Name, schedule, cancellationToken: cancellationToken); + } + + private async Task FlattenProperties(CancellationToken cancellationToken) + { + await _elasticClient.Indices.PutMappingAsync( + descriptor => descriptor + .Properties(p => p + .Flattened(d => d + .Name(p => p.WorkflowState.Properties))), + cancellationToken); + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; +} \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Implementations/RolloverStrategies/RolloverOnMonthlyBasis.cs b/src/modules/Elsa.Elasticsearch/Implementations/RolloverStrategies/RolloverOnMonthlyBasis.cs new file mode 100644 index 000000000..0fa2b8cfc --- /dev/null +++ b/src/modules/Elsa.Elasticsearch/Implementations/RolloverStrategies/RolloverOnMonthlyBasis.cs @@ -0,0 +1,35 @@ +using Elsa.Elasticsearch.Common; +using Elsa.Elasticsearch.Services; +using Nest; + +namespace Elsa.Elasticsearch.Implementations.RolloverStrategies; + +public class RolloverOnMonthlyBasis : IRolloverStrategy +{ + private readonly ElasticClient _client; + + public RolloverOnMonthlyBasis(ElasticClient client) + { + _client = client; + } + + public void Apply(IEnumerable types, IDictionary aliasConfig) + { + foreach (var type in types) + { + var aliasName = aliasConfig[type]; + var indexName = Utils.GenerateIndexName(aliasName); + + var indexExists = _client.Indices.Exists(indexName).Exists; + + if (indexExists) continue; + + var response = _client.Indices.Create(indexName, s => s + .Aliases(a => a.Alias(aliasName)) + .Map(m => m.AutoMap(type))); + + if (response.IsValid) continue; + throw response.OriginalException; + } + } +} \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Models/IndexRolloverStrategy.cs b/src/modules/Elsa.Elasticsearch/Models/IndexRolloverStrategy.cs new file mode 100644 index 000000000..e41c014ec --- /dev/null +++ b/src/modules/Elsa.Elasticsearch/Models/IndexRolloverStrategy.cs @@ -0,0 +1,17 @@ +using Elsa.Elasticsearch.Implementations.RolloverStrategies; + +namespace Elsa.Elasticsearch.Models; + +public class IndexRolloverStrategy +{ + private IndexRolloverStrategy(Type value) { Value = value; } + + public Type Value { get; private set; } + + public static IndexRolloverStrategy RolloverOnMonthlyBasis => new (typeof(RolloverOnMonthlyBasis)); + + public override string ToString() + { + return Value.Name; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Modules/Management/Extensions.cs b/src/modules/Elsa.Elasticsearch/Modules/Management/Extensions.cs index 72fff722b..affa55a70 100644 --- a/src/modules/Elsa.Elasticsearch/Modules/Management/Extensions.cs +++ b/src/modules/Elsa.Elasticsearch/Modules/Management/Extensions.cs @@ -1,3 +1,5 @@ +using Elsa.Elasticsearch.Common; +using Elsa.Elasticsearch.Models; using Elsa.Elasticsearch.Options; using Elsa.Workflows.Management.Features; @@ -8,12 +10,18 @@ public static class Extensions /// /// Configures the to use the . /// - public static WorkflowInstanceFeature UseElasticsearch(this WorkflowInstanceFeature feature, ElasticsearchOptions options, IDictionary? aliasConfig = default, Action? configure = default) + public static WorkflowInstanceFeature UseElasticsearch( + this WorkflowInstanceFeature feature, + ElasticsearchOptions options, + IndexRolloverStrategy? rolloverStrategy = default, + IDictionary? indexConfig = default, + Action? configure = default) { configure += f => { f.Options = options; - f.AliasConfig = aliasConfig ?? options.Aliases ?? f.AliasConfig; + f.IndexRolloverStrategy = rolloverStrategy; + f.IndexConfig = Utils.ResolveAliasConfig(f.IndexConfig, options.IndexConfig, indexConfig); }; feature.Module.Configure(configure); diff --git a/src/modules/Elsa.Elasticsearch/Modules/Management/WorkflowInstanceConfiguration.cs b/src/modules/Elsa.Elasticsearch/Modules/Management/WorkflowInstanceConfiguration.cs index ee0195cf7..71e8b7406 100644 --- a/src/modules/Elsa.Elasticsearch/Modules/Management/WorkflowInstanceConfiguration.cs +++ b/src/modules/Elsa.Elasticsearch/Modules/Management/WorkflowInstanceConfiguration.cs @@ -6,11 +6,11 @@ namespace Elsa.Elasticsearch.Modules.Management; public class WorkflowInstanceConfiguration : ElasticConfiguration { - public override void Apply(ConnectionSettings connectionSettings, IDictionary aliasConfig) + public override void Apply(ConnectionSettings connectionSettings, IDictionary indexConfig) { connectionSettings .DefaultMappingFor(m => m - .IndexName(aliasConfig[nameof(WorkflowInstance)]) + .IndexName(indexConfig[typeof(WorkflowInstance)]) .Ignore(p => p.WorkflowState)); } } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Modules/Runtime/ExecutionLogConfiguration.cs b/src/modules/Elsa.Elasticsearch/Modules/Runtime/ExecutionLogConfiguration.cs index 93ecfeed6..726323bc9 100644 --- a/src/modules/Elsa.Elasticsearch/Modules/Runtime/ExecutionLogConfiguration.cs +++ b/src/modules/Elsa.Elasticsearch/Modules/Runtime/ExecutionLogConfiguration.cs @@ -6,9 +6,9 @@ namespace Elsa.Elasticsearch.Modules.Runtime; public class ExecutionLogConfiguration : ElasticConfiguration { - public override void Apply(ConnectionSettings connectionSettings, IDictionary aliasConfig) + public override void Apply(ConnectionSettings connectionSettings, IDictionary indexConfig) { connectionSettings.DefaultMappingFor(m => - m.IndexName(aliasConfig[nameof(WorkflowExecutionLogRecord)])); + m.IndexName(indexConfig[typeof(WorkflowExecutionLogRecord)])); } } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Modules/Runtime/Extensions.cs b/src/modules/Elsa.Elasticsearch/Modules/Runtime/Extensions.cs index 11aa83e11..ed137b0a0 100644 --- a/src/modules/Elsa.Elasticsearch/Modules/Runtime/Extensions.cs +++ b/src/modules/Elsa.Elasticsearch/Modules/Runtime/Extensions.cs @@ -1,3 +1,5 @@ +using Elsa.Elasticsearch.Common; +using Elsa.Elasticsearch.Models; using Elsa.Elasticsearch.Options; using Elsa.Workflows.Runtime.Features; @@ -8,12 +10,18 @@ public static class Extensions /// /// Configures the to use the . /// - public static ExecutionLogRecordFeature UseElasticsearch(this ExecutionLogRecordFeature feature, ElasticsearchOptions options, IDictionary? aliasConfig = default, Action? configure = default) + public static ExecutionLogRecordFeature UseElasticsearch( + this ExecutionLogRecordFeature feature, + ElasticsearchOptions options, + IndexRolloverStrategy? rolloverStrategy = default, + IDictionary? indexConfig = default, + Action? configure = default) { configure += f => { f.Options = options; - f.AliasConfig = aliasConfig ?? options.Aliases ?? f.AliasConfig; + f.IndexRolloverStrategy = rolloverStrategy; + f.IndexConfig = Utils.ResolveAliasConfig(f.IndexConfig, options.IndexConfig, indexConfig); }; feature.Module.Configure(configure); diff --git a/src/modules/Elsa.Elasticsearch/Options/ElasticsearchOptions.cs b/src/modules/Elsa.Elasticsearch/Options/ElasticsearchOptions.cs index 9411cd351..a027b3212 100644 --- a/src/modules/Elsa.Elasticsearch/Options/ElasticsearchOptions.cs +++ b/src/modules/Elsa.Elasticsearch/Options/ElasticsearchOptions.cs @@ -4,7 +4,7 @@ public class ElasticsearchOptions { public const string Elasticsearch = "Elasticsearch"; - public Dictionary? Aliases { get; set; } + public Dictionary? IndexConfig { get; set; } public string Endpoint { get; set; } public string Username { get; set; } public string Password { get; set; } diff --git a/src/modules/Elsa.Scheduling/Jobs/ConfigureElasticIndicesJob.cs b/src/modules/Elsa.Elasticsearch/Scheduling/ConfigureElasticIndicesJob.cs similarity index 97% rename from src/modules/Elsa.Scheduling/Jobs/ConfigureElasticIndicesJob.cs rename to src/modules/Elsa.Elasticsearch/Scheduling/ConfigureElasticIndicesJob.cs index 925557af9..39facb32a 100644 --- a/src/modules/Elsa.Scheduling/Jobs/ConfigureElasticIndicesJob.cs +++ b/src/modules/Elsa.Elasticsearch/Scheduling/ConfigureElasticIndicesJob.cs @@ -4,7 +4,7 @@ using Elsa.Jobs.Models; using Nest; using Job = Elsa.Jobs.Abstractions.Job; -namespace Elsa.Scheduling.Jobs; +namespace Elsa.Elasticsearch.Scheduling; public class ConfigureElasticIndicesJob : Job { diff --git a/src/modules/Elsa.Elasticsearch/Services/IElasticConfiguration.cs b/src/modules/Elsa.Elasticsearch/Services/IElasticConfiguration.cs index e46855e2a..3c09a2e1f 100644 --- a/src/modules/Elsa.Elasticsearch/Services/IElasticConfiguration.cs +++ b/src/modules/Elsa.Elasticsearch/Services/IElasticConfiguration.cs @@ -5,10 +5,10 @@ namespace Elsa.Elasticsearch.Services; public interface IElasticConfiguration { - void Apply(ConnectionSettings connectionSettings, IDictionary aliasConfig); + void Apply(ConnectionSettings connectionSettings, IDictionary indexConfig); - public static IDictionary GetDefaultAliasConfig() + public static IDictionary GetDefaultIndexConfig() { - return Utils.GetElasticDocumentTypes().ToDictionary(type => type.Name, type => type.Name.ToLower()); + return Utils.GetElasticDocumentTypes().ToDictionary(type => type, type => type.Name.ToLower()); } } \ No newline at end of file diff --git a/src/modules/Elsa.Elasticsearch/Services/IRolloverStrategy.cs b/src/modules/Elsa.Elasticsearch/Services/IRolloverStrategy.cs new file mode 100644 index 000000000..be93e3f6b --- /dev/null +++ b/src/modules/Elsa.Elasticsearch/Services/IRolloverStrategy.cs @@ -0,0 +1,6 @@ +namespace Elsa.Elasticsearch.Services; + +public interface IRolloverStrategy +{ + void Apply(IEnumerable types, IDictionary aliasConfig); +} \ No newline at end of file diff --git a/src/modules/Elsa.Quartz/Extensions/DependencyInjectionExtensions.cs b/src/modules/Elsa.Quartz/Extensions/DependencyInjectionExtensions.cs index d3a16f4b0..bfe1f29fa 100644 --- a/src/modules/Elsa.Quartz/Extensions/DependencyInjectionExtensions.cs +++ b/src/modules/Elsa.Quartz/Extensions/DependencyInjectionExtensions.cs @@ -1,3 +1,4 @@ +using Elsa.Elasticsearch.Scheduling; using Elsa.Quartz.Jobs; using Elsa.Scheduling.Jobs; using Quartz; diff --git a/src/modules/Elsa.Scheduling/Features/SchedulingFeature.cs b/src/modules/Elsa.Scheduling/Features/SchedulingFeature.cs index 79b064e06..ec84b8180 100644 --- a/src/modules/Elsa.Scheduling/Features/SchedulingFeature.cs +++ b/src/modules/Elsa.Scheduling/Features/SchedulingFeature.cs @@ -27,7 +27,6 @@ public class SchedulingFeature : FeatureBase Services .AddSingleton() .AddSingleton() - .AddSingleton() .AddNotificationHandlersFrom(); Module.Configure(management => management.AddActivitiesFrom()); diff --git a/src/modules/Elsa.Scheduling/Implementations/ElasticCongurationScheduler.cs b/src/modules/Elsa.Scheduling/Implementations/ElasticCongurationScheduler.cs deleted file mode 100644 index 1279872fb..000000000 --- a/src/modules/Elsa.Scheduling/Implementations/ElasticCongurationScheduler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Elsa.Jobs.Schedules; -using Elsa.Jobs.Services; -using Elsa.Scheduling.Jobs; -using Elsa.Scheduling.Services; - -namespace Elsa.Scheduling.Implementations; - -public class ElasticCongurationScheduler : IElasticCongurationScheduler -{ - private readonly IJobScheduler _jobScheduler; - - public ElasticCongurationScheduler(IJobScheduler jobScheduler) - { - _jobScheduler = jobScheduler; - } - - public async Task ScheduleAsync(CancellationToken cancellationToken = default) - { - var job = new ConfigureElasticIndicesJob(); - var schedule = new CronSchedule - { - //Last day of every month - CronExpression = "0 18 L * ?" - }; - - await _jobScheduler.ScheduleAsync(job, GetType().Name, schedule, cancellationToken: cancellationToken); - } -} \ No newline at end of file diff --git a/src/modules/Elsa.Scheduling/Services/IElasticCongurationScheduler.cs b/src/modules/Elsa.Scheduling/Services/IElasticCongurationScheduler.cs deleted file mode 100644 index ad63b296a..000000000 --- a/src/modules/Elsa.Scheduling/Services/IElasticCongurationScheduler.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Elsa.Workflows.Core.Models; - -namespace Elsa.Scheduling.Services; - -public interface IElasticCongurationScheduler -{ - Task ScheduleAsync(CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/State/ExceptionState.cs b/src/modules/Elsa.Workflows.Core/State/ExceptionState.cs index ba35fb57e..3204f76e8 100644 --- a/src/modules/Elsa.Workflows.Core/State/ExceptionState.cs +++ b/src/modules/Elsa.Workflows.Core/State/ExceptionState.cs @@ -7,7 +7,7 @@ namespace Elsa.Workflows.Core.State; /// /// A simplified, serializable model representing an exception. /// -public record ExceptionState(Type Type, string Message, string? StackTrace, IDictionary Data, ExceptionState? InnerException = default) +public record ExceptionState(Type Type, string Message, string? StackTrace, ExceptionState? InnerException = default) { // /// // /// Constructor @@ -26,6 +26,6 @@ public record ExceptionState(Type Type, string Message, string? StackTrace, IDic if (ex == null) return null; - return new ExceptionState(ex.GetType(), ex.Message, ex.StackTrace, ex.Data, FromException(ex.InnerException)); + return new ExceptionState(ex.GetType(), ex.Message, ex.StackTrace, FromException(ex.InnerException)); } } \ No newline at end of file