Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response body emitter #2724

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ generic-service:
INTEGRATIONS_TIER_URL: https://hmpps-tier-dev.hmpps.service.justice.gov.uk
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer
CRN-STREAMING_TIMEOUT: 10800000
CRN-STREAMING_TIMEOUT: "10800000"

LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG

Expand Down
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ generic-service:
INTEGRATIONS_TIER_URL: https://hmpps-tier-preprod.hmpps.service.justice.gov.uk
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer
CRN-STREAMING_TIMEOUT: 21600000L
CRN-STREAMING_TIMEOUT: "21600000"

generic-prometheus-alerts:
businessHoursOnly: true
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ generic-service:
INTEGRATIONS_TIER_URL: https://hmpps-tier.hmpps.service.justice.gov.uk
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer
CRN-STREAMING_TIMEOUT: 21600000L
CRN-STREAMING_TIMEOUT: "21600000"
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package uk.gov.justice.digital.hmpps.controller

import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType
import org.springframework.stereotype.Controller
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
import uk.gov.justice.digital.hmpps.service.CrnStreamingService
import java.util.concurrent.Executors

Expand All @@ -18,11 +19,11 @@ class CrnEmitter(
private val executorService = Executors.newSingleThreadExecutor()

@GetMapping("/probation-cases")
fun handleSse(): SseEmitter = SseEmitter(timeout).also { emitter ->
fun handleSse(): ResponseBodyEmitter = ResponseBodyEmitter(timeout).also { emitter ->
executorService.execute {
TransactionTemplate(transactionManager).execute {
crnStreamingService.getActiveCrns().use { stream ->
stream.forEach { emitter.send(it) }
stream.forEach { emitter.send(it + System.lineSeparator(), MediaType.TEXT_PLAIN) }
emitter.complete()
}
}
Expand Down