Skip to content

Commit

Permalink
[ML4SE-249] Changed coroutine scopes for file sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 authored and nbirillo committed Dec 11, 2023
1 parent 6d7a592 commit 19f4caf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.forms.*
import io.ktor.http.*
import kotlinx.coroutines.runBlocking
import org.apache.http.client.utils.URIBuilder
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig.Companion.getRoute
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
Expand All @@ -17,7 +16,7 @@ object FileRequests {
private val logger: Logger = Logger.getInstance(FileRequests::class.java)

@Suppress("TooGenericExceptionCaught")
fun sendFile(file: File, logFileType: String) = runBlocking {
suspend fun sendFile(file: File, logFileType: String): Boolean {
try {
val researchId = GlobalPluginStorage.currentResearchId
?: error("ResearchId is undefined")
Expand All @@ -37,13 +36,12 @@ object FileRequests {
)
}
)
true
return true
} catch (e: IllegalStateException) {
logger.warn(e.localizedMessage)
false
} catch (e: Exception) {
logger.warn("Server interaction error! File to send: ${file.path}", e)
false
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Loggable {

abstract fun getLogFiles(): List<File>

fun send() = getLogFiles().all {
suspend fun send() = getLogFiles().all {
FileRequests.sendFile(it, this.logFileType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.jetbrains.research.tasktracker.tracking.logger

import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.research.tasktracker.requests.FileRequests
import java.io.File

Expand All @@ -23,8 +25,10 @@ object DocumentLogger {
?: emptyList<File>().also {
logger.error("attempt to flush non-existing csv printer for document '$document'")
}
logFiles.all {
FileRequests.sendFile(it, "document")
logFiles.forEach {
GlobalScope.launch {
FileRequests.sendFile(it, "document")
}
}
myDocumentsToPrinters.remove(document)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBPanel
import com.intellij.ui.jcef.JBCefApp
import com.intellij.util.ui.JBUI
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import org.jetbrains.concurrency.Promise
import org.jetbrains.research.tasktracker.config.content.task.base.Task
Expand Down Expand Up @@ -90,8 +92,10 @@ class MainPluginPanelFactory : ToolWindowFactory {
trackers.forEach {
it.stopTracking()
}
trackers.forEach {
it.send()
GlobalScope.launch {
trackers.forEach {
it.send()
}
}
}

Expand Down

0 comments on commit 19f4caf

Please sign in to comment.