mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
19 lines
702 B
C#
19 lines
702 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 BaseWorker[] DoWorkInternal()
|
|
{
|
|
IQueryable<Notification> toRemove = DbContext.Notifications.Where(n => n.IsSent || DateTime.UtcNow - n.Date > Interval);
|
|
DbContext.Remove(toRemove);
|
|
DbContext.Sync();
|
|
return [];
|
|
}
|
|
|
|
} |