in service/src/main/java/org/apache/fineract/cn/rhythm/service/internal/service/Drummer.java [67:109]
public synchronized void checkForBeatsNeeded() {
logger.info("checkForBeatsNeeded begin.");
//In it's current form this function cannot be run in multiple instances of the same service. We need to get
//locking on selected entries corrected here, before this will work.
try {
final LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
//Get beats from the last two hours in case restart/start happens close to hour begin.
final Stream<BeatEntity> beats = beatRepository.findByNextBeatBefore(now);
beats.forEach((beat) -> {
final boolean applicationHasRequestForAccessPermission
= identityPermittableGroupService.checkThatApplicationHasRequestForAccessPermission(
beat.getTenantIdentifier(), beat.getApplicationIdentifier());
if (!applicationHasRequestForAccessPermission) {
logger.info("Not checking if beat {} needs publishing, because application access needed to publish is not available.", beat);
}
else {
logger.info("Checking if beat {} needs publishing.", beat);
final LocalDateTime nextBeat = checkBeatForPublish(
now,
beat.getBeatIdentifier(),
beat.getTenantIdentifier(),
beat.getApplicationIdentifier(),
beat.getAlignmentHour(),
beat.getNextBeat());
if (!nextBeat.equals(beat.getNextBeat())) {
beat.setNextBeat(nextBeat);
beatRepository.save(beat);
}
logger.info("Beat updated to {}.", beat);
}
});
}
catch (final PessimisticLockingFailureException e) {
if (e.getMessage() != null && e.getMessage().contains("relation \"khepri_beats\" does not exist")) {
logger.info("Exception in check for scheduled beats as table khepri_beats does not exist. Probably cause initialize hasn't been called yet.");
}
else {
logger.warn("PessimisticLockingFailureException in check for scheduled beats", e);
}
}
logger.info("checkForBeatsNeeded end.");
}