use of com.redhat.cloud.notifications.models.Notification in project notifications-backend by RedHatInsights.
the class EmailSender method sendEmail.
public Optional<NotificationHistory> sendEmail(User user, Event event, TemplateInstance subject, TemplateInstance body) {
final HttpRequest<Buffer> bopRequest = this.buildBOPHttpRequest();
LocalDateTime start = LocalDateTime.now(UTC);
Action action = event.getAction();
Timer.Sample processedTimer = Timer.start(registry);
// uses canonical EmailSubscription
try {
Endpoint endpoint = endpointRepository.getOrCreateDefaultEmailSubscription(action.getAccountId());
Notification notification = new Notification(event, endpoint);
// TODO Add recipients processing from policies-notifications processing (failed recipients)
// by checking the NotificationHistory's details section (if missing payload - fix in WebhookTypeProcessor)
// TODO If the call fails - we should probably rollback Kafka topic (if BOP is down for example)
// also add metrics for these failures
NotificationHistory history = webhookSender.doHttpRequest(notification, bopRequest, getPayload(user, action, subject, body));
processedTimer.stop(registry.timer("processor.email.processed", "bundle", action.getBundle(), "application", action.getApplication()));
processTime.record(Duration.between(start, LocalDateTime.now(UTC)));
return Optional.of(history);
} catch (Exception e) {
logger.info("Email sending failed", e);
return Optional.empty();
}
}
Aggregations