diff --git a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs index df4314a1b..1c79d69b0 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs @@ -31,8 +31,6 @@ namespace Elsa.Workflows.Runtime.Features; [DependsOn(typeof(SystemClockFeature))] public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module) { - private bool _enableWorkflowInboxCleanupJob = true; - private IDictionary WorkflowDispatcherChannels { get; set; } = new Dictionary(); /// @@ -134,7 +132,7 @@ public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module) /// public WorkflowRuntimeFeature EnableWorkflowInboxCleanupJob() { - _enableWorkflowInboxCleanupJob = true; + Services.Configure(options => { options.IsEnabled = true; }); return this; } @@ -143,7 +141,7 @@ public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module) /// public WorkflowRuntimeFeature DisableWorkflowInboxCleanupJob() { - _enableWorkflowInboxCleanupJob = false; + Services.Configure(options => { options.IsEnabled = false; }); return this; } @@ -203,7 +201,7 @@ public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module) public override void ConfigureHostedServices() { Module.ConfigureHostedService(); - if (_enableWorkflowInboxCleanupJob) Module.ConfigureHostedService(); + Module.ConfigureHostedService(); } /// diff --git a/src/modules/Elsa.Workflows.Runtime/HostedServices/WorkflowInboxCleanupHostedService.cs b/src/modules/Elsa.Workflows.Runtime/HostedServices/WorkflowInboxCleanupHostedService.cs index 28804c504..22f12e5cc 100644 --- a/src/modules/Elsa.Workflows.Runtime/HostedServices/WorkflowInboxCleanupHostedService.cs +++ b/src/modules/Elsa.Workflows.Runtime/HostedServices/WorkflowInboxCleanupHostedService.cs @@ -32,6 +32,12 @@ public class WorkflowInboxCleanupHostedService : BackgroundService /// protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + if (!_options.Value.IsEnabled) + { + _logger.LogInformation("Expired workflow inbox messages cleanup service is disabled"); + return; + } + while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Entering expired workflow inbox messages cleanup service loop"); diff --git a/src/modules/Elsa.Workflows.Runtime/Options/WorkflowInboxCleanupOptions.cs b/src/modules/Elsa.Workflows.Runtime/Options/WorkflowInboxCleanupOptions.cs index fc694689e..7aa1266d8 100644 --- a/src/modules/Elsa.Workflows.Runtime/Options/WorkflowInboxCleanupOptions.cs +++ b/src/modules/Elsa.Workflows.Runtime/Options/WorkflowInboxCleanupOptions.cs @@ -14,4 +14,9 @@ public class WorkflowInboxCleanupOptions /// The number of messages to clean up per sweep. /// public int BatchSize { get; set; } = 1000; + + /// + /// Whether the workflow inbox cleanup is enabled. + /// + public bool IsEnabled { get; set; } = true; } \ No newline at end of file