use of com.epam.pipeline.notifier.service.task.NotificationManager in project cloud-pipeline by epam.
the class NotificationService method sendNotification.
/**
* Scheduled task to load batch of {@link NotificationMessage} from database
* and delegate it to all realizations of {@link NotificationManager}
*/
@Scheduled(fixedDelayString = "${notification.scheduler.delay}")
@Transactional(propagation = Propagation.REQUIRED)
public void sendNotification() {
LOGGER.debug("Start scheduled notification loop...");
Pageable limit = new PageRequest(0, notificationAtTime);
List<NotificationMessage> result = notificationRepository.loadNotification(limit);
result.forEach(message -> {
notificationRepository.deleteById(message.getId());
for (NotificationManager notificationManager : notificationManagers) {
CompletableFuture.runAsync(() -> notificationManager.notifySubscribers(message), notificationThreadPool).exceptionally(throwable -> {
LOGGER.warn("Exception while trying to send email", throwable);
return null;
});
}
});
LOGGER.debug("End scheduled notification loop...");
}
Aggregations