From ef9efb253e12a8f1cdc12dd04286f19223536f03 Mon Sep 17 00:00:00 2001 From: Elizabeth Paige Harper Date: Tue, 14 May 2024 14:44:26 -0400 Subject: [PATCH] ref #297: mark import as failed when input file processing fails --- .../service/vdi/service/datasets/create-dataset.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/service/rest-service/src/main/kotlin/org/veupathdb/service/vdi/service/datasets/create-dataset.kt b/service/rest-service/src/main/kotlin/org/veupathdb/service/vdi/service/datasets/create-dataset.kt index fb7a744e..1f746e73 100644 --- a/service/rest-service/src/main/kotlin/org/veupathdb/service/vdi/service/datasets/create-dataset.kt +++ b/service/rest-service/src/main/kotlin/org/veupathdb/service/vdi/service/datasets/create-dataset.kt @@ -110,7 +110,11 @@ fun createDataset( // starting the new thread. Then the new thread will be forked and the // target file downloaded into a temp directory in that thread before // being uploaded to MinIO (also in that forked thread). - val (tempDirectory, uploadFile) = entity.getDatasetFile() + val (tempDirectory, uploadFile) = try { entity.getDatasetFile() } + catch (e: Throwable) { + CacheDB().withTransaction { it.updateImportControl(datasetID, DatasetImportStatus.Failed) } + throw e + } Metrics.Upload.queueSize.inc() WorkPool.submit { @@ -374,8 +378,12 @@ private fun DatasetPostRequest.getDatasetFile(): Pair = // Try to establish a connection to the URL target (validating that the // target is reachable) - val connection = try { url.openConnection() } - catch (e: Throwable) { throw BadRequestException("given source file URL was unreachable") } + val connection = try { + url.openConnection() + } catch (e: Throwable) { + paths.first.deleteRecursively() + throw BadRequestException("given source file URL was unreachable") + } // Try to download the file from the source URL. try {