Status controller


Tue Nov 09 2021 05:00:39 GMT+0000 (UTC)

Saved by @delitescere #lowjs #hotwire #thymeleaf #html

internal class StatusController @Autowired constructor(private val supervisor: ObserveeSupervisor) {
    @GetMapping("/status", produces = [MediaType.TEXT_HTML_VALUE])
    suspend fun index(model: Model): String {
        val observees = ObserveeInfo.from(supervisor.observeeHealthFlows)
        model.addAttribute("observees", observees)
        return "status"

     * Stream of change to health status of any Observee
    @GetMapping("/", produces = [MediaType.TEXT_EVENT_STREAM_VALUE, CustomMediaType.TURBO_STREAM_VALUE])
    suspend fun stream(model: Model): String {
        val observees = ObserveeInfo.from(supervisor.observeeHealthFlows.asFlow())
        model.addAttribute("observees", dataDrivenEach(observees))
        return "observee-status.turbo-stream"

    private fun dataDrivenEach(stream: Flow<Any>) = ReactiveDataDriverContextVariable(stream, 1)