Browse Source

Add support to customize the interval of cleaning messages for collector. (#973)

master
Savorboard 3 years ago
parent
commit
e6ffdea3b9
2 changed files with 11 additions and 2 deletions
  1. +7
    -0
      src/DotNetCore.CAP/CAP.Options.cs
  2. +4
    -2
      src/DotNetCore.CAP/Processor/IProcessor.Collector.cs

+ 7
- 0
src/DotNetCore.CAP/CAP.Options.cs View File

@@ -26,6 +26,7 @@ namespace DotNetCore.CAP
Extensions = new List<ICapOptionsExtension>();
Version = "v1";
DefaultGroupName = "cap.queue." + Assembly.GetEntryAssembly()?.GetName().Name.ToLower();
CollectorCleaningInterval = 300;
}

internal IList<ICapOptionsExtension> Extensions { get; }
@@ -85,6 +86,12 @@ namespace DotNetCore.CAP
/// </summary>
public int ProducerThreadCount { get; set; }

/// <summary>
/// The interval of the collector processor deletes expired messages.
/// Default is 300 seconds.
/// </summary>
public int CollectorCleaningInterval { get; set; }

/// <summary>
/// Registers an extension that will be executed when building services.
/// </summary>


+ 4
- 2
src/DotNetCore.CAP/Processor/IProcessor.Collector.cs View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using DotNetCore.CAP.Persistence;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace DotNetCore.CAP.Processor
{
@@ -15,15 +16,16 @@ namespace DotNetCore.CAP.Processor
private readonly IServiceProvider _serviceProvider;

private const int ItemBatch = 1000;
private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5);
private readonly TimeSpan _waitingInterval;
private readonly TimeSpan _delay = TimeSpan.FromSeconds(1);

private readonly string[] _tableNames;

public CollectorProcessor(ILogger<CollectorProcessor> logger, IServiceProvider serviceProvider)
public CollectorProcessor(ILogger<CollectorProcessor> logger, IOptions<CapOptions> options, IServiceProvider serviceProvider)
{
_logger = logger;
_serviceProvider = serviceProvider;
_waitingInterval = TimeSpan.FromSeconds(options.Value.CollectorCleaningInterval);

var initializer = _serviceProvider.GetService<IStorageInitializer>();



Loading…
Cancel
Save