mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
StartNewChapterDownloadsWorker.cs
This commit is contained in:
29
API/Workers/PeriodicWorkers/SendNotificationsWorker.cs
Normal file
29
API/Workers/PeriodicWorkers/SendNotificationsWorker.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using API.Schema.NotificationsContext;
|
||||
using API.Schema.NotificationsContext.NotificationConnectors;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class SendNotificationsWorker(TimeSpan? interval = null, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<NotificationsContext>(dependsOn), IPeriodic
|
||||
{
|
||||
public DateTime LastExecution { get; set; } = DateTime.UtcNow;
|
||||
public TimeSpan Interval { get; set; } = interval??TimeSpan.FromMinutes(1);
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
NotificationConnector[] connectors = DbContext.NotificationConnectors.ToArray();
|
||||
Notification[] notifications = DbContext.Notifications.Where(n => n.IsSent == false).ToArray();
|
||||
|
||||
foreach (Notification notification in notifications)
|
||||
{
|
||||
foreach (NotificationConnector connector in connectors)
|
||||
{
|
||||
connector.SendNotification(notification.Title, notification.Message);
|
||||
notification.IsSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
DbContext.Sync();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user