From 006581135451facf1e3e821960691ff59f0c6c43 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 17 Feb 2025 19:04:10 +0100 Subject: [PATCH] Add toggle for WorkflowInboxCleanupJob in WorkflowRuntimeFeature Introduced methods to enable or disable the WorkflowInboxCleanupJob. Updated service configuration logic to conditionally register WorkflowInboxCleanupHostedService based on the toggle. This adds flexibility to control cleanup job behavior programmatically. --- .../Features/WorkflowRuntimeFeature.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs index 3dc91ed49..df4314a1b 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs @@ -29,12 +29,9 @@ namespace Elsa.Workflows.Runtime.Features; /// Installs and configures workflow runtime features. /// [DependsOn(typeof(SystemClockFeature))] -public class WorkflowRuntimeFeature : FeatureBase +public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module) { - /// - public WorkflowRuntimeFeature(IModule module) : base(module) - { - } + private bool _enableWorkflowInboxCleanupJob = true; private IDictionary WorkflowDispatcherChannels { get; set; } = new Dictionary(); @@ -126,12 +123,30 @@ public class WorkflowRuntimeFeature : FeatureBase /// A delegate to configure the . /// public Action WorkflowInboxCleanupOptions { get; set; } = _ => { }; - + /// /// A delegate to configure the . /// public Action WorkflowDispatcherOptions { get; set; } = _ => { }; + /// + /// Enables the workflow inbox cleanup job. + /// + public WorkflowRuntimeFeature EnableWorkflowInboxCleanupJob() + { + _enableWorkflowInboxCleanupJob = true; + return this; + } + + /// + /// Disables the workflow inbox cleanup job. + /// + public WorkflowRuntimeFeature DisableWorkflowInboxCleanupJob() + { + _enableWorkflowInboxCleanupJob = false; + return this; + } + /// /// Register the specified workflow type. /// @@ -188,7 +203,7 @@ public class WorkflowRuntimeFeature : FeatureBase public override void ConfigureHostedServices() { Module.ConfigureHostedService(); - Module.ConfigureHostedService(); + if (_enableWorkflowInboxCleanupJob) Module.ConfigureHostedService(); } /// @@ -240,7 +255,7 @@ public class WorkflowRuntimeFeature : FeatureBase .AddScoped() .AddScoped, ActivityExecutionRecordExtractor>() .AddScoped, WorkflowExecutionLogRecordExtractor>() - + // Stores. .AddScoped(BookmarkStore) .AddScoped(TriggerStore)