Skip to content

Commit

Permalink
fix(server): add logs while processing "cleanup" command
Browse files Browse the repository at this point in the history
  • Loading branch information
clementguillot committed Jun 3, 2024
1 parent e092111 commit 1e2fa79
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.jboss.logging.Logger
import org.nxcloudce.server.domain.run.gateway.ArtifactRepository
import org.nxcloudce.server.domain.run.gateway.RunRepository
import org.nxcloudce.server.domain.run.gateway.StorageService
Expand All @@ -18,11 +19,16 @@ class CleanupRunImpl(
private val artifactRepository: ArtifactRepository,
private val storageService: StorageService,
) : CleanupRun {
companion object {
private val logger = Logger.getLogger(CleanupRunImpl::class.java)
}

override suspend fun <T> invoke(
request: CleanupRunRequest,
presenter: (CleanupRunResponse) -> T,
): T {
val runs = runRepository.findAllByCreationDateOlderThan(request.creationDateThreshold)
logger.info("Found run(s) to delete: ${runs.size}")

runs.forEach { run ->
val tasks = taskRepository.findAllByRunId(run.id)
Expand All @@ -31,6 +37,7 @@ class CleanupRunImpl(
tasks.filter { it.artifactId != null }.map { it.hash },
run.workspaceId,
)
logger.info("Run contains ${tasks.size} task(s) and ${artifacts.size} artifact(s)")

coroutineScope {
artifacts.map { artifact ->
Expand All @@ -43,10 +50,12 @@ class CleanupRunImpl(
}
}
.awaitAll()
logger.info("Artifacts and their files have deleted")
coroutineScope {
launch { taskRepository.deleteAllByRunId(run.id) }
launch { runRepository.delete(run) }
}
logger.info("Tasks and run have been deleted")
}

return presenter(CleanupRunResponse(deletedCount = runs.size))
Expand Down

0 comments on commit 1e2fa79

Please sign in to comment.