Skip to content

Commit c00d11a

Browse files
Merge branch 'MIG/stop_scenariorun_does_not_work_PROD-12524'
2 parents 5c6c8bc + 5229d1d commit c00d11a

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/service/ScenarioRunServiceImpl.kt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,29 @@ class ScenarioRunServiceImpl(
677677
val scenarioRun =
678678
this.findScenarioRunById(organizationId, scenariorunId, withStateInformation = false)
679679
// This call verify by itself that we have the read authorization in the scenario
680-
scenarioApiService.findScenarioById(
681-
organizationId, scenarioRun.workspaceId!!, scenarioRun.scenarioId!!)
682-
return getScenarioRunStatus(organizationId, scenarioRun)
680+
val scenario =
681+
scenarioApiService.findScenarioById(
682+
organizationId, scenarioRun.workspaceId!!, scenarioRun.scenarioId!!)
683+
684+
// PROD-12524
685+
// due to the hack do not check the status as usual as we forced the scenario's status to failed
686+
val scenariorRunStatus = getScenarioRunStatus(organizationId, scenarioRun)
687+
if (scenario.state == ScenarioJobState.Failed) {
688+
return ScenarioRunStatus(
689+
id = scenariorRunStatus.id,
690+
organizationId = scenariorRunStatus.organizationId,
691+
workflowId = scenariorRunStatus.workflowId,
692+
workflowName = scenariorRunStatus.workflowName,
693+
startTime = scenariorRunStatus.startTime,
694+
endTime = scenariorRunStatus.endTime,
695+
phase = scenariorRunStatus.state.toString(),
696+
progress = scenariorRunStatus.progress,
697+
message = scenariorRunStatus.message,
698+
estimatedDuration = scenariorRunStatus.estimatedDuration,
699+
nodes = scenariorRunStatus.nodes)
700+
}
701+
702+
return scenariorRunStatus
683703
}
684704

685705
private fun getScenarioRunStatus(
@@ -857,10 +877,19 @@ class ScenarioRunServiceImpl(
857877

858878
override fun stopScenarioRun(organizationId: String, scenariorunId: String): ScenarioRunStatus {
859879
val scenarioRun = findScenarioRunById(organizationId, scenariorunId)
860-
val scenario =
880+
var scenario =
861881
scenarioApiService.findScenarioById(
862882
organizationId, scenarioRun.workspaceId!!, scenarioRun.scenarioId!!)
863883
csmRbac.verify(scenario.getRbac(), PERMISSION_WRITE, scenarioPermissions)
884+
// PROD-12524
885+
// As the workflow is not stopping when trying to stop it(argo version 0.16.6)
886+
// the workaround is to set the scenario's state to failed
887+
scenario.state = ScenarioJobState.Failed
888+
eventPublisher.publishEvent(
889+
ScenarioLastRunChanged(this, organizationId, scenarioRun.workspaceId, scenario))
890+
891+
val sr = scenarioRun.copy(state = ScenarioRunState.Failed)
892+
scenarioRunRepository.save(sr)
864893
return workflowService.stopWorkflow(findScenarioRunById(organizationId, scenariorunId))
865894
}
866895

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/workflow/argo/ArgoWorkflowService.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.cosmotech.scenariorun.domain.ScenarioRunContainerLogs
1212
import com.cosmotech.scenariorun.domain.ScenarioRunLogs
1313
import com.cosmotech.scenariorun.domain.ScenarioRunResourceRequested
1414
import com.cosmotech.scenariorun.domain.ScenarioRunStartContainers
15+
import com.cosmotech.scenariorun.domain.ScenarioRunState
1516
import com.cosmotech.scenariorun.domain.ScenarioRunStatus
1617
import com.cosmotech.scenariorun.domain.ScenarioRunStatusNode
1718
import com.cosmotech.scenariorun.workflow.WorkflowContextData
@@ -437,7 +438,9 @@ internal class ArgoWorkflowService(
437438
workflowName = scenarioRun.workflowName,
438439
startTime = workflowStatus?.startedAt?.toString(),
439440
endTime = workflowStatus?.finishedAt?.toString(),
440-
phase = workflowStatus?.phase,
441+
phase =
442+
if (scenarioRun.state == ScenarioRunState.Failed) ScenarioRunState.Failed.toString()
443+
else workflowStatus?.phase,
441444
progress = workflowStatus?.progress,
442445
message = workflowStatus?.message,
443446
estimatedDuration = workflowStatus?.estimatedDuration,

0 commit comments

Comments
 (0)