Skip to content

Commit

Permalink
Revert "Be more conservative about piping server progress through Web…
Browse files Browse the repository at this point in the history
…sockets"

This reverts commit c6cfe2e.
  • Loading branch information
gregorbg committed Jan 19, 2024
1 parent d1009d5 commit 6bfe686
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,7 +53,7 @@ class WcifHandler(val environmentConfig: ServerEnvironmentConfig) : RouteHandler

override suspend fun ScramblingJobData.compute(statusBackend: StatusBackend): Pair<ContentType, ByteArray> {
val wcif = WCIFScrambleMatcher.fillScrambleSetsAsync(request.wcif) { evt, _ ->
runBlocking { statusBackend.onProgress(evt.id) }
statusBackend.onProgress(evt.id)
}

return scrambledToResult(this, wcif, statusBackend)
Expand Down

0 comments on commit 6bfe686

Please sign in to comment.