Files
agrynco aba4173827 feat(templates): add localized push templates and actions
Share template keys across email and push with independent editors and revisions. Render localized actions and preserve version-one delivery.

Ref: IT-1627
2026-10-31 09:38:05 +02:00

43 lines
1.9 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)
{
if (message?.Data is { } data && !PushMessageValidator.IsSupportedVersion(data.Version))
{
validationError = "Unsupported push payload version. Supported versions are 1 and 2.";
return false;
}
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);
}
}