From 6bfe686a463c1afa8816a7935e53bc6c1f442e32 Mon Sep 17 00:00:00 2001 From: Gregor Billing Date: Fri, 19 Jan 2024 20:56:21 +0100 Subject: [PATCH] Revert "Be more conservative about piping server progress through Websockets" This reverts commit c6cfe2edc53fc1c3b1bfcb47286d4e7349c767fb. --- .../tnoodle/server/job/StatusBackend.kt | 13 +++++++------ .../tnoodle/server/routing/WcifHandler.kt | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt index 105f99aab..9dfdeedb8 100644 --- a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt +++ b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt @@ -2,21 +2,22 @@ package org.worldcubeassociation.tnoodle.server.job import io.ktor.websocket.* import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch sealed class StatusBackend { - abstract suspend fun onProgress(worker: String) + abstract fun onProgress(worker: String) class JobRegistry(val jobId: Int) : StatusBackend() { - override suspend fun onProgress(worker: String) = JobSchedulingHandler.registerProgress(jobId, worker) + override fun onProgress(worker: String) = JobSchedulingHandler.registerProgress(jobId, worker) } - data object NoOp : StatusBackend() { - override suspend fun onProgress(worker: String) {} + object NoOp : StatusBackend() { + override fun onProgress(worker: String) {} } class Websocket(val socket: WebSocketSession) : StatusBackend(), CoroutineScope by socket { - override suspend fun onProgress(worker: String) { - socket.send(worker) + override fun onProgress(worker: String) { + launch { socket.send(worker) } } } } diff --git a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt index e8b710860..9e9b31c2b 100644 --- a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt +++ b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt @@ -5,7 +5,6 @@ import io.ktor.server.application.* import io.ktor.server.request.* import io.ktor.server.routing.* import io.ktor.websocket.* -import kotlinx.coroutines.runBlocking import kotlinx.serialization.encodeToString import org.worldcubeassociation.tnoodle.server.RouteHandler import org.worldcubeassociation.tnoodle.server.serial.JsonConfig @@ -54,7 +53,7 @@ class WcifHandler(val environmentConfig: ServerEnvironmentConfig) : RouteHandler override suspend fun ScramblingJobData.compute(statusBackend: StatusBackend): Pair { val wcif = WCIFScrambleMatcher.fillScrambleSetsAsync(request.wcif) { evt, _ -> - runBlocking { statusBackend.onProgress(evt.id) } + statusBackend.onProgress(evt.id) } return scrambledToResult(this, wcif, statusBackend)