Skip to content

Commit a5fdb36

Browse files
committed
Fix deleteRun
1 parent 7079a8d commit a5fdb36

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

run/src/main/kotlin/com/cosmotech/run/service/RunEventServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RunEventServiceImpl(private val runApiService: RunApiServiceInterface) :
3131
hasRunningRuns.response =
3232
runApiService.listAllRuns(organizationId, workspaceId, runnerId).any {
3333
val runState =
34-
runApiService.getRunStatus(organizationId, workspaceId, runnerId, it.id!!).state
34+
runApiService.getRun(organizationId, workspaceId, runnerId, it.id!!).state
3535
?: RunState.Unknown
3636
runState == RunState.Running
3737
}

run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -452,27 +452,28 @@ class RunServiceImpl(
452452

453453
workflowService.stopWorkflow(run)
454454

455-
if (csmPlatformProperties.internalResultServices?.enabled == true)
456-
adminRunStorageTemplate.dropDB(run.id!!)
457-
458-
runRepository.delete(run)
459-
460-
val runs = listRuns(run.organizationId!!, run.workspaceId!!, run.runnerId!!, null, null)
461-
var lastRun: String? = null
462-
var lastStart: Long = 0
463-
if (runs.isNotEmpty()) {
464-
runs.forEach {
465-
if (it.createInfo.timestamp >= lastStart) {
466-
lastStart = it.createInfo.timestamp
467-
lastRun = it.id!!
455+
val defaultPageSize = csmPlatformProperties.twincache.run.defaultPageSize
456+
val pageRequest = PageRequest.ofSize(defaultPageSize)
457+
val runs =
458+
runRepository
459+
.findByRunnerId(run.organizationId!!, run.workspaceId!!, run.runnerId!!, pageRequest)
460+
.toList()
461+
462+
val previousRuns = runs.filter { it.id != run.id }
463+
val lastRun =
464+
if (previousRuns.isEmpty()) {
465+
null
466+
} else {
467+
previousRuns.maxBy { it.createInfo.timestamp }.id
468468
}
469-
}
470-
} else {
471-
lastRun = null
472-
}
473469
val runDeleted =
474470
RunDeleted(this, run.organizationId, run.workspaceId, run.runnerId, run.id!!, lastRun)
475471
this.eventPublisher.publishEvent(runDeleted)
472+
473+
if (csmPlatformProperties.internalResultServices?.enabled == true)
474+
adminRunStorageTemplate.dropDB(run.id)
475+
476+
runRepository.delete(run)
476477
} catch (exception: IllegalStateException) {
477478
logger.debug(
478479
"An error occurred while deleting Run {}: {}", run.id, exception.message, exception)

0 commit comments

Comments
 (0)