Skip to content

Commit

Permalink
Merge pull request #6429 from elsa-workflows/bug/disable-inbox-cleanup
Browse files Browse the repository at this point in the history
Enable configurable toggle for workflow inbox cleanup job
  • Loading branch information
sfmskywalker authored Feb 21, 2025
2 parents 6ccf52f + d7900ef commit 7ea0137
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, DispatcherChannel> WorkflowDispatcherChannels { get; set; } = new Dictionary<string, DispatcherChannel>();

/// <summary>
Expand Down Expand Up @@ -134,7 +132,7 @@ public class WorkflowRuntimeFeature(IModule module) : FeatureBase(module)
/// </summary>
public WorkflowRuntimeFeature EnableWorkflowInboxCleanupJob()
{
_enableWorkflowInboxCleanupJob = true;
Services.Configure<WorkflowInboxCleanupOptions>(options => { options.IsEnabled = true; });
return this;
}

Expand All @@ -143,7 +141,7 @@ public WorkflowRuntimeFeature EnableWorkflowInboxCleanupJob()
/// </summary>
public WorkflowRuntimeFeature DisableWorkflowInboxCleanupJob()
{
_enableWorkflowInboxCleanupJob = false;
Services.Configure<WorkflowInboxCleanupOptions>(options => { options.IsEnabled = false; });
return this;
}

Expand Down Expand Up @@ -203,7 +201,7 @@ public override void Configure()
public override void ConfigureHostedServices()
{
Module.ConfigureHostedService<PopulateRegistriesHostedService>();
if (_enableWorkflowInboxCleanupJob) Module.ConfigureHostedService<WorkflowInboxCleanupHostedService>();
Module.ConfigureHostedService<WorkflowInboxCleanupHostedService>();
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public WorkflowInboxCleanupHostedService(
/// <inheritdoc />
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public class WorkflowInboxCleanupOptions
/// The number of messages to clean up per sweep.
/// </summary>
public int BatchSize { get; set; } = 1000;

/// <summary>
/// Whether the workflow inbox cleanup is enabled.
/// </summary>
public bool IsEnabled { get; set; } = true;
}

0 comments on commit 7ea0137

Please sign in to comment.