-
Notifications
You must be signed in to change notification settings - Fork 46
/
ExpiredDocumentsCleaner.cs
41 lines (33 loc) · 2.04 KB
/
ExpiredDocumentsCleaner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace ServiceControl.Infrastructure.RavenDB.Expiration
{
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using BackgroundTasks;
using NServiceBus.Logging;
using Raven.Abstractions;
using Raven.Database;
using SagaAudit;
using ServiceBus.Management.Infrastructure.Settings;
class ExpiredDocumentsCleaner
{
public static Task<TimerJobExecutionResult> RunCleanup(int deletionBatchSize, DocumentDatabase database, Settings settings, CancellationToken cancellationToken = default)
{
var threshold = SystemTime.UtcNow.Add(-settings.ErrorRetentionPeriod);
logger.Debug($"Trying to find expired FailedMessage documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
ErrorMessageCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
threshold = SystemTime.UtcNow.Add(-settings.EventsRetentionPeriod);
logger.Debug($"Trying to find expired EventLogItem documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
EventLogItemsCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
if (settings.AuditRetentionPeriod.HasValue)
{
threshold = SystemTime.UtcNow.Add(-settings.AuditRetentionPeriod.Value);
logger.Debug($"Trying to find expired ProcessedMessage and SagaHistory documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
AuditMessageCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
SagaHistoryCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
}
return Task.FromResult(TimerJobExecutionResult.ScheduleNextExecution);
}
static ILog logger = LogManager.GetLogger(typeof(ExpiredDocumentsCleaner));
}
}