Skip to content
Permalink
Browse files
Merge pull request #15 from aasaru/FINCN-177
FINCN-177 catch actual exception and detect problem by error message
  • Loading branch information
Izakey committed Oct 15, 2019
2 parents 7f1556f + 346a349 commit 9f108954b9e6dfc337dc40933326425711f564d7
Showing 2 changed files with 21 additions and 15 deletions.
@@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.apache.fineract.cn.anubis.api.v1.domain.AllowedOperation;
import org.apache.fineract.cn.api.context.AutoUserContext;
import org.apache.fineract.cn.api.util.ApiFactory;
@@ -163,8 +164,8 @@ public boolean publishBeat(
}
catch (final Throwable e) {
logger.warn("Unable to publish beat '{}' to application '{}' for tenant '{}', " +
"because exception was thrown in publish {}.", beatIdentifier, applicationIdentifier, tenantIdentifier, e);
"because exception was thrown in publish.", beatIdentifier, applicationIdentifier, tenantIdentifier, e);
return false;
}
}
}
}
@@ -22,6 +22,7 @@
import java.time.LocalDateTime;
import java.util.function.Predicate;
import java.util.stream.Stream;

import org.apache.fineract.cn.rhythm.api.v1.domain.ClockOffset;
import org.apache.fineract.cn.rhythm.service.ServiceConstants;
import org.apache.fineract.cn.rhythm.service.internal.mapper.BeatMapper;
@@ -31,7 +32,7 @@
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -73,20 +74,20 @@ public synchronized void checkForBeatsNeeded() {
final Stream<BeatEntity> beats = beatRepository.findByNextBeatBefore(now);
beats.forEach((beat) -> {
final boolean applicationHasRequestForAccessPermission
= identityPermittableGroupService.checkThatApplicationHasRequestForAccessPermission(
beat.getTenantIdentifier(), beat.getApplicationIdentifier());
= 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());
now,
beat.getBeatIdentifier(),
beat.getTenantIdentifier(),
beat.getApplicationIdentifier(),
beat.getAlignmentHour(),
beat.getNextBeat());
if (!nextBeat.equals(beat.getNextBeat())) {
beat.setNextBeat(nextBeat);
beatRepository.save(beat);
@@ -96,9 +97,13 @@ public synchronized void checkForBeatsNeeded() {
});

}
catch (final InvalidDataAccessResourceUsageException e) {
logger.info("InvalidDataAccessResourceUsageException in check for scheduled beats, probably " +
"because initialize hasn't been called yet. {}", e);
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.");
}
@@ -163,4 +168,4 @@ static LocalDateTime incrementToAlignment(
{
return BeatMapper.alignDateTime(toIncrement.plusDays(1), alignmentHour, clockOffset);
}
}
}

0 comments on commit 9f10895

Please sign in to comment.