Skip to content

Commit 044347a

Browse files
PI-1846 ignore data integrity violation (duplicate key) exceptions
1 parent 99577b7 commit 044347a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppstier/service/TierCalculationService.kt

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uk.gov.justice.digital.hmpps.hmppstier.service
22

33
import org.slf4j.LoggerFactory
4+
import org.springframework.dao.DataIntegrityViolationException
45
import org.springframework.stereotype.Service
56
import uk.gov.justice.digital.hmpps.hmppstier.client.AssessmentForTier
67
import uk.gov.justice.digital.hmpps.hmppstier.client.NeedSection
@@ -58,6 +59,10 @@ class TierCalculationService(
5859
)
5960
}
6061
} catch (e: Exception) {
62+
if (e is DataIntegrityViolationException) {
63+
log.error("Multiple concurrent attempts to calculate tier for $crn => $recalculationSource")
64+
return
65+
}
6166
val eventType = if (allowUpdates) TIER_CALCULATION_FAILED else TIER_RECALCULATION_DRY_RUN_FAILURE
6267
telemetryService.trackEvent(
6368
eventType,

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppstier/service/TierUpdater.kt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.hmppstier.service
22

33
import org.springframework.data.repository.findByIdOrNull
44
import org.springframework.stereotype.Service
5+
import org.springframework.transaction.annotation.Propagation
56
import org.springframework.transaction.annotation.Transactional
67
import uk.gov.justice.digital.hmpps.hmppstier.jpa.entity.TierCalculationEntity
78
import uk.gov.justice.digital.hmpps.hmppstier.jpa.entity.TierSummary
@@ -14,6 +15,7 @@ class TierUpdater(
1415
private val tierSummaryRepository: TierSummaryRepository,
1516
) {
1617

18+
@Transactional(propagation = Propagation.REQUIRES_NEW)
1719
fun removeTierCalculationsFor(crn: String) {
1820
tierCalculationRepository.deleteAllByCrn(crn)
1921
tierSummaryRepository.deleteById(crn)

0 commit comments

Comments
 (0)