mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
20 lines
763 B
C#
20 lines
763 B
C#
using API.Schema.NotificationsContext;
|
|
|
|
namespace API.Workers.MaintenanceWorkers;
|
|
|
|
public class RemoveOldNotificationsWorker(TimeSpan? interval = null, IEnumerable<BaseWorker>? dependsOn = null)
|
|
: BaseWorkerWithContext<NotificationsContext>(dependsOn), IPeriodic
|
|
{
|
|
public DateTime LastExecution { get; set; } = DateTime.UnixEpoch;
|
|
public TimeSpan Interval { get; set; } = interval ?? TimeSpan.FromHours(1);
|
|
|
|
protected override async Task<BaseWorker[]> DoWorkInternal()
|
|
{
|
|
IQueryable<Notification> toRemove = DbContext.Notifications.Where(n => n.IsSent || DateTime.UtcNow - n.Date > Interval);
|
|
DbContext.RemoveRange(toRemove);
|
|
|
|
await DbContext.Sync(CancellationTokenSource.Token);
|
|
return [];
|
|
}
|
|
|
|
} |