diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/GitService.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/GitService.kt index 4ba78604d6ef047ab0bf7071e9a09d81204d47bb..bce20555dc5225a1fbb759fbbee03a1770961f3a 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/GitService.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/GitService.kt @@ -1,8 +1,8 @@ package de.fraunhofer.iem.dataprovider.git +import de.fraunhofer.iem.dataprovider.taskManager.TaskManager import org.springframework.stereotype.Service -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.* + @Service class GitService(private val taskManager: TaskManager) { diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/TaskManager.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/TaskManager.kt similarity index 57% rename from src/main/kotlin/de/fraunhofer/iem/dataprovider/git/TaskManager.kt rename to src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/TaskManager.kt index 5d335adae5860ecdf52b057c42440f336e28974b..e974fa7faefbbddfd62f317ab1c031388f430d1c 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/git/TaskManager.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/TaskManager.kt @@ -1,5 +1,6 @@ -package de.fraunhofer.iem.dataprovider.git +package de.fraunhofer.iem.dataprovider.taskManager +import de.fraunhofer.iem.dataprovider.logger.getLogger import jakarta.annotation.PostConstruct import jakarta.annotation.PreDestroy import kotlinx.coroutines.* @@ -7,6 +8,10 @@ import kotlinx.coroutines.channels.Channel import org.springframework.stereotype.Component import kotlin.coroutines.CoroutineContext +enum class TaskType{ + REPO_CHANGED +} +data class Task(val type: TaskType, val payload: Any) @Component class TaskManager : CoroutineScope { @@ -16,21 +21,25 @@ class TaskManager : CoroutineScope { // TODO: this could be dangerous to give it unlimited memory private val tasks = Channel<String>(Channel.UNLIMITED) + private val numCores = Runtime.getRuntime().availableProcessors() + private val logger = getLogger(javaClass) @PostConstruct fun startWorkers() { - // TODO: spawn threads equal to number of cores - repeat(10) { - println("[${Thread.currentThread().name}] launching coroutine") + logger.info("Starting $numCores workers.") + repeat(numCores-1) { + logger.info("[${Thread.currentThread().name}] launching coroutine") launchWorker(it) } } private fun launchWorker(id: Int) = launch { for (task in tasks) { - println("[${Thread.currentThread().name}] Processor #$id received $task") - executeTask(task) - println("[${Thread.currentThread().name}] Processor #$id finished $task") + launch { + logger.debug("[${Thread.currentThread().name}] Processor #$id received $task") + executeTask(task) + logger.debug("[${Thread.currentThread().name}] Processor #$id finished $task") + } } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f763c5957d5e7d57260330ac10f1c81fb1aeda21..db2873267210a0439e74f78b34e251630fce14c0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,5 @@ spring.config.import=optional:classpath:.env[.properties] OPENCODE_GITLAB_URL=https://gitlab.opencode.de/ OPENCODE_GITLAB_TOKEN=${OPENCODE_TOKEN} -spring.r2dbc.url=${R2DBC_URL} \ No newline at end of file +spring.r2dbc.url=${R2DBC_URL} +logging.level.root=DEBUG \ No newline at end of file