Skip to content
Snippets Groups Projects
Verified Commit 1bb7acb8 authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

added test endpoint.

added external process task
parent 837901cd
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ package de.fraunhofer.iem.dataprovider.gitlab ...@@ -2,7 +2,7 @@ package de.fraunhofer.iem.dataprovider.gitlab
import de.fraunhofer.iem.dataprovider.logger.getLogger import de.fraunhofer.iem.dataprovider.logger.getLogger
import de.fraunhofer.iem.dataprovider.taskManager.TaskManager import de.fraunhofer.iem.dataprovider.taskManager.TaskManager
import de.fraunhofer.iem.dataprovider.taskManager.tasks.ProcessTask import de.fraunhofer.iem.dataprovider.taskManager.tasks.JavaTask
import de.fraunhofer.iem.dataprovider.taskManager.tasks.TaskType import de.fraunhofer.iem.dataprovider.taskManager.tasks.TaskType
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PostMapping
...@@ -51,6 +51,6 @@ class GitlabController(private val gitlabService: GitlabService, private val tas ...@@ -51,6 +51,6 @@ class GitlabController(private val gitlabService: GitlabService, private val tas
@GetMapping("/test") @GetMapping("/test")
suspend fun test() { suspend fun test() {
taskManager.addTask(ProcessTask(TaskType.REPO_CHANGED)) taskManager.addTask(JavaTask(TaskType.REPO_CHANGED, "-version", responseChannel = taskManager::addTask ))
} }
} }
\ No newline at end of file
...@@ -36,15 +36,16 @@ class TaskManager: IWorker { ...@@ -36,15 +36,16 @@ class TaskManager: IWorker {
private fun CoroutineScope.taskActor() = actor<ITask> { private fun CoroutineScope.taskActor() = actor<ITask> {
for (task in channel) { for (task in channel) {
logger.info("[${Thread.currentThread().name}] add task called in Task Manager $task")
// For test purposes we have the Done task, which prints a control // For test purposes we have the Done task, which prints a control
// message printed in the task manager. // message printed in the task manager.
if (task.type == TaskType.DONE) { if (task.type == TaskType.DONE) {
task.execute() task.execute()
} } else {
logger.info("[${Thread.currentThread().name}] add task called in Task Manager $task") when (task) {
when(task) { is GetGitlabProjectTask -> ioWorker.addTask(task)
is GetGitlabProjectTask -> ioWorker.addTask(task) else -> worker.addTask(task)
else -> worker.addTask(task) }
} }
logger.info("[${Thread.currentThread().name}] add task finished in Task Manager $task") logger.info("[${Thread.currentThread().name}] add task finished in Task Manager $task")
} }
......
package de.fraunhofer.iem.dataprovider.taskManager.tasks package de.fraunhofer.iem.dataprovider.taskManager.tasks
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
sealed class ProcessTask(protected open vararg val flags: String): Task() { sealed class ProcessTask(protected open vararg val flags: String): Task() {
protected abstract val execPath: String protected abstract val execPath: String
private val mainScope = CoroutineScope(Dispatchers.Default)
override suspend fun execute() { override suspend fun execute() {
val p = ProcessBuilder(execPath, *flags) val p = ProcessBuilder(execPath, *flags)
.start() .start()
p.onExit().thenApply { p1 -> p.onExit().thenApply { p1 ->
handleProcessReturn(p1) mainScope.launch {
handleProcessReturn(p1)
}
} }
} }
abstract fun handleProcessReturn(p: Process) abstract suspend fun handleProcessReturn(p: Process)
} }
class JavaTask( class JavaTask(
override val type: TaskType, override val type: TaskType,
override val execPath: String,
override vararg val flags: String, override vararg val flags: String,
val addTask: (task: Task) -> Unit private val responseChannel: suspend (task: ITask) -> Unit
): ProcessTask() { ): ProcessTask() {
override fun handleProcessReturn(p: Process) { override val execPath: String = "java"
addTask(DoneTask("Done with external process. Exit value ${p.exitValue()}")) override suspend fun handleProcessReturn(p: Process) {
responseChannel(DoneTask("Done with external process. Exit value ${p.exitValue()}"))
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.