Skip to content

Commit 1839f21

Browse files
committed
Replace exception-based handling with logging for stopping already finished runs
- Updated `RunnerApiServiceImpl` to log a debug message instead of throwing an `IllegalStateException` when attempting to stop a finished run. - Adjusted corresponding integration tests to validate the updated behavior using `assertDoesNotThrow`.
1 parent 59bacd3 commit 1839f21

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import io.mockk.junit5.MockKExtension
5555
import io.mockk.mockk
5656
import io.mockk.mockkStatic
5757
import java.io.FileInputStream
58-
import java.lang.IllegalStateException
5958
import java.time.Instant
6059
import java.util.*
6160
import kotlin.test.assertEquals
@@ -1516,12 +1515,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() {
15161515
val run = runnerApiService.startRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
15171516
assertEquals(expectedRunId, run.id)
15181517

1519-
val exception =
1520-
assertThrows<IllegalStateException> {
1521-
runnerApiService.stopRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
1522-
}
1523-
1524-
assertEquals("Run $expectedRunId can not be stopped as its already finished", exception.message)
1518+
assertDoesNotThrow {
1519+
runnerApiService.stopRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
1520+
}
15251521
}
15261522

15271523
@Test
@@ -1543,12 +1539,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() {
15431539
val run = runnerApiService.startRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
15441540
assertEquals(expectedRunId, run.id)
15451541

1546-
val exception =
1547-
assertThrows<IllegalStateException> {
1548-
runnerApiService.stopRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
1549-
}
1550-
1551-
assertEquals("Run $expectedRunId can not be stopped as its already finished", exception.message)
1542+
assertDoesNotThrow {
1543+
runnerApiService.stopRun(organizationSaved.id, workspaceSaved.id, runnerSaved.id)
1544+
}
15521545
}
15531546

15541547
@Test

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.cosmotech.runner.domain.RunnerCreateRequest
2323
import com.cosmotech.runner.domain.RunnerRole
2424
import com.cosmotech.runner.domain.RunnerSecurity
2525
import com.cosmotech.runner.domain.RunnerUpdateRequest
26+
import org.slf4j.LoggerFactory
2627
import org.springframework.context.event.EventListener
2728
import org.springframework.data.domain.PageRequest
2829
import org.springframework.stereotype.Service
@@ -34,6 +35,9 @@ internal class RunnerApiServiceImpl(
3435
private val runnerServiceManager: RunnerServiceManager,
3536
private val datasetApiServiceInterface: DatasetApiServiceInterface
3637
) : RunnerApiServiceInterface {
38+
39+
private val logger = LoggerFactory.getLogger(RunnerApiServiceImpl::class.java)
40+
3741
override fun getRunnerService(): RunnerService = runnerServiceManager.getRunnerService()
3842

3943
override fun createRunner(
@@ -141,8 +145,8 @@ internal class RunnerApiServiceImpl(
141145
runnerService.stopLastRunOf(runnerInstance)
142146
return
143147
}
144-
throw IllegalStateException(
145-
"Run ${lastRunInfo.lastRunId} can not be stopped as its already finished")
148+
149+
logger.debug("Run ${lastRunInfo.lastRunId} can not be stopped as its already finished")
146150
}
147151

148152
override fun createRunnerAccessControl(

0 commit comments

Comments
 (0)