Search in sources :

Example 1 with Notification

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();
    }
}
Also used : Buffer(io.vertx.mutiny.core.buffer.Buffer) LocalDateTime(java.time.LocalDateTime) Action(com.redhat.cloud.notifications.ingress.Action) Timer(io.micrometer.core.instrument.Timer) Endpoint(com.redhat.cloud.notifications.models.Endpoint) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) Notification(com.redhat.cloud.notifications.models.Notification)

Aggregations

Action (com.redhat.cloud.notifications.ingress.Action)1 Endpoint (com.redhat.cloud.notifications.models.Endpoint)1 Notification (com.redhat.cloud.notifications.models.Notification)1 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)1 Timer (io.micrometer.core.instrument.Timer)1 Buffer (io.vertx.mutiny.core.buffer.Buffer)1 LocalDateTime (java.time.LocalDateTime)1