58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
using System;
|
|
|
|
namespace Svrnty.CQRS.Events.PostgreSQL.Retention;
|
|
|
|
/// <summary>
|
|
/// Configuration options for the retention policy background service.
|
|
/// </summary>
|
|
public class RetentionServiceOptions
|
|
{
|
|
/// <summary>
|
|
/// How often to check and enforce retention policies.
|
|
/// Default: 1 hour
|
|
/// </summary>
|
|
public TimeSpan CleanupInterval { get; set; } = TimeSpan.FromHours(1);
|
|
|
|
/// <summary>
|
|
/// Start of cleanup window (UTC time of day).
|
|
/// Cleanup only runs during this window to avoid peak hours.
|
|
/// Default: 2 AM UTC
|
|
/// </summary>
|
|
public TimeSpan CleanupWindowStart { get; set; } = TimeSpan.FromHours(2);
|
|
|
|
/// <summary>
|
|
/// End of cleanup window (UTC time of day).
|
|
/// Default: 6 AM UTC
|
|
/// </summary>
|
|
public TimeSpan CleanupWindowEnd { get; set; } = TimeSpan.FromHours(6);
|
|
|
|
/// <summary>
|
|
/// Whether the retention service is enabled.
|
|
/// If false, retention policies will not be enforced automatically.
|
|
/// Default: true
|
|
/// </summary>
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Whether to use the cleanup window restriction.
|
|
/// If false, cleanup runs whenever the interval elapses, regardless of time.
|
|
/// Default: true
|
|
/// </summary>
|
|
public bool UseCleanupWindow { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Validates the configuration.
|
|
/// </summary>
|
|
public void Validate()
|
|
{
|
|
if (CleanupInterval <= TimeSpan.Zero)
|
|
throw new ArgumentException("CleanupInterval must be positive", nameof(CleanupInterval));
|
|
|
|
if (CleanupWindowStart < TimeSpan.Zero || CleanupWindowStart >= TimeSpan.FromHours(24))
|
|
throw new ArgumentException("CleanupWindowStart must be between 00:00:00 and 23:59:59", nameof(CleanupWindowStart));
|
|
|
|
if (CleanupWindowEnd < TimeSpan.Zero || CleanupWindowEnd >= TimeSpan.FromHours(24))
|
|
throw new ArgumentException("CleanupWindowEnd must be between 00:00:00 and 23:59:59", nameof(CleanupWindowEnd));
|
|
}
|
|
}
|