use of com.pratilipi.common.util.Async in project pratilipi by Pratilipi.
the class NotificationProcessApi method get.
@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Notification> notifList = dataAccessor.getNotificationListWithFcmPending(1000);
logger.log(Level.INFO, "Total pending notifications = " + notifList.size());
Map<Long, List<Notification>> userIdNotifListMap = new HashMap<>();
for (Notification notif : notifList) {
List<Notification> userNotifList = userIdNotifListMap.get(notif.getUserId());
if (userNotifList == null) {
userNotifList = new LinkedList<>();
userIdNotifListMap.put(notif.getUserId(), userNotifList);
}
userNotifList.add(notif);
}
for (final Entry<Long, List<Notification>> entry : userIdNotifListMap.entrySet()) {
Async async = new Async() {
@Override
public void exec() {
for (Notification notif : entry.getValue()) {
Task task = TaskQueueFactory.newTask().setUrl("/notification/process").addParam("notificationId", notif.getId().toString());
TaskQueueFactory.getNotificationTaskQueue().add(task);
logger.log(Level.INFO, "Task created for notification id " + notif.getId());
}
}
};
NotificationDataUtil.updateFirebaseDb(entry.getKey(), entry.getValue(), async);
}
return new GenericResponse();
}
Aggregations