Skip to content

Commit

Permalink
PI-2032 Publish messages using default thread pool (#3541)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Mar 25, 2024
1 parent 2858ac0 commit 32c7d8c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ internal class PrisonMatchingIntegrationTest {
.perform(post("/person/match-by-crn?dryRun=false").withToken().withJson(listOf(crn)))
.andExpect(status().is2xxSuccessful)

verify(telemetryService, timeout(300_000)).trackEvent(
verify(telemetryService, timeout(5000)).trackEvent(
"MatchResultSuccess", mapOf(
"reason" to "Matched CRN A000003 to NOMS number G5541WW and custody $custodyId to 13831A",
"crn" to "A000003",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MatchingController(private val notifier: Notifier) {
@Size(min = 1, max = 500, message = "Please provide between 1 and 500 CRNs. Leave blank to match all CRNs.")
@RequestBody crns: List<String>?
) {
Thread.ofVirtual().start { notifier.requestPrisonMatching(crns ?: listOf(), dryRun) }
notifier.requestPrisonMatching(crns ?: listOf(), dryRun)
}

@ResponseStatus(HttpStatus.ACCEPTED)
Expand All @@ -29,6 +29,6 @@ class MatchingController(private val notifier: Notifier) {
@Size(min = 1, max = 500, message = "Please provide between 1 and 500 NOMS numbers.")
@RequestBody nomsNumbers: List<String>
) {
Thread.ofVirtual().start { notifier.requestProbationMatching(nomsNumbers, dryRun) }
notifier.requestProbationMatching(nomsNumbers, dryRun)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.digital.hmpps.messaging

import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.entity.PersonRepository
import uk.gov.justice.digital.hmpps.message.*
Expand All @@ -18,12 +19,14 @@ class Notifier(
const val REQUEST_PROBATION_MATCH = "prison-identifier.internal.probation-match-requested"
}

@Async
fun requestPrisonMatching(crns: List<String>, dryRun: Boolean) {
crns.ifEmpty { personRepository.findAllCrns() }.asSequence()
.map { notification(REQUEST_PRISON_MATCH, PersonIdentifier("CRN", it), dryRun) }
.forEach { queuePublisher.publish(it) }
}

@Async
fun requestProbationMatching(nomsNumbers: List<String>, dryRun: Boolean) {
nomsNumbers.asSequence()
.map { notification(REQUEST_PROBATION_MATCH, PersonIdentifier("NOMS", it), dryRun) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spring:
provider:
hmpps-auth:
token-uri: http://localhost:${wiremock.port}/auth/oauth/token
threads.virtual.enabled: true
threads.virtual.enabled: false

springdoc.default-produces-media-type: application/json

Expand Down

0 comments on commit 32c7d8c

Please sign in to comment.