Files
hrynco-notification-service/HrynCo.NotificationService.Worker/SendPushConsumer.cs
T
agrynco 1631786ce2 feat(push): add service-owned firebase channels and delivery
Add push contracts, provider delivery and channel diagnostics. Link email channels to services and document migration and validation.

Ref: IT-1074
2026-10-24 12:31:35 +03:00

38 lines
1.6 KiB
C#

namespace HrynCo.NotificationService.Worker;
using HrynCo.NotificationService.Contracts.Messages;
using HrynCo.NotificationService.Worker.Services.Push;
using Hrynco.RabbitMq;
using Microsoft.Extensions.Options;
public sealed class SendPushConsumer(
IOptionsMonitor<RabbitMqSettings> options, IServiceScopeFactory scopes,
ILogger<SendPushConsumer> logger)
: RabbitMqConsumerBase<SendPushMessage, SendPushMessageData>(options, logger)
{
protected override string QueueName => "notification.send-push";
protected override bool TryValidateMessage(SendPushMessage message, RabbitMqMessageContext context, out string? validationError)
{
bool valid = SendPushDeliveryValidator.IsValid(message, context);
validationError = valid ? null : "Invalid push envelope.";
return valid;
}
protected override async Task HandleMessageAsync(SendPushMessage message, RabbitMqMessageContext context,
CancellationToken cancellationToken)
{
await using var scope = scopes.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<PushDeliveryService>()
.ProcessAsync(Guid.Parse(context.MessageId!), message, cancellationToken);
}
protected override async Task HandleMessageRetriesExhaustedAsync(SendPushMessage message,
RabbitMqMessageContext context, Exception exception, CancellationToken cancellationToken)
{
await using var scope = scopes.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<PushDeliveryService>()
.CompleteFailureAsync(Guid.Parse(context.MessageId!), message, cancellationToken);
}
}