feat: добавил отправку уведомлений по почте
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 10s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m17s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 12s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 10s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m17s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 12s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using UniVerse.Application.DTOs.Notifications;
|
||||
using UniVerse.Application.Interfaces;
|
||||
|
||||
namespace UniVerse.Infrastructure.Notifications;
|
||||
|
||||
[DisallowConcurrentExecution]
|
||||
public class NotificationJob : IJob
|
||||
{
|
||||
public const string MessageDataKey = "message";
|
||||
|
||||
private readonly INotificationService _notifications;
|
||||
private readonly ILogger<NotificationJob> _logger;
|
||||
|
||||
public NotificationJob(INotificationService notifications, ILogger<NotificationJob> logger)
|
||||
{
|
||||
_notifications = notifications;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
var payload = context.MergedJobDataMap.GetString(MessageDataKey);
|
||||
if (string.IsNullOrWhiteSpace(payload))
|
||||
{
|
||||
_logger.LogWarning("Notification job {JobKey} does not contain message payload", context.JobDetail.Key);
|
||||
return;
|
||||
}
|
||||
|
||||
var message = JsonSerializer.Deserialize<NotificationMessage>(payload)
|
||||
?? throw new InvalidOperationException("Scheduled notification payload cannot be deserialized.");
|
||||
|
||||
await _notifications.SendAsync(message, context.CancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user