Verified Commit 199ed678 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

delete cached thumbnails

parent 84d55d6e
Pipeline #42096 passed with stages
in 4 minutes and 54 seconds
......@@ -17,6 +17,7 @@ elasticIndexConfigs: prod-documents-index
mediaVolumeClaimName: "media-volume-claim"
mediaFolderRootPath: "/data"
mediaFolderCacheRootPath: "/data/cached"
mariadbDatabaseConfigs: prod-mariadb-db-medienserver-configs
mariadbUserSecrets: prod-mariadb-user-medienserver-secrets
......
......@@ -17,6 +17,7 @@ elasticIndexConfigs: stage-documents-index
mediaVolumeClaimName: "stage-media-volume-claim"
mediaFolderRootPath: "/data"
mediaFolderCacheRootPath: "/data/cached"
mariadbDatabaseConfigs: stage-mariadb-db-medienserver-configs
mariadbUserSecrets: stage-mariadb-user-medienserver-secrets
......
......@@ -17,6 +17,7 @@ elasticIndexConfigs: test-documents-index
mediaVolumeClaimName: "test-media-volume-claim"
mediaFolderRootPath: "/data"
mediaFolderCacheRootPath: "/data/cached"
mariadbDatabaseConfigs: test-mariadb-db-medienserver-configs
mariadbUserSecrets: test-mariadb-user-medienserver-secrets
......
......@@ -9,3 +9,4 @@ data:
TOPIC_PROCESS: "{{ .Values.reportingTopicName }}"
MARIADB_TABLES: "{{ .Values.mariadbTables }}"
MEDIA_FOLDER_ROOT_PATH: "{{ .Values.mediaFolderRootPath}}"
MEDIA_FOLDER_CACHE_ROOT_PATH: "{{ .Values.mediaFolderCacheRootPath}}"
......@@ -23,6 +23,7 @@ elasticIndexConfigs: placeholder
mediaVolumeClaimName: placeholder
mediaFolderRootPath: placeholder
mediaFolderCacheRootPath: placeholder
mariadbDatabaseConfigs: placeholder
mariadbUserSecrets: placeholder
......
......@@ -41,6 +41,7 @@ object App
.map(rec => if (rec.dryRun) existsInES(rec) else deleteInES(rec))
.map(rec => deleteMariaDBEntries(rec))
.map(rec => deleteBinaries(rec))
.map(rec => deleteCachedBinaries(rec))
.foreach(rec => reportResult(rec))
} catch {
case e: Exception =>
......
......@@ -71,5 +71,6 @@ trait AppSettings {
.toList
val mariaDBUser: String = sys.env("MARIADB_USER").replaceAll("\\s+$", "")
val mediaFolderRootPath: String = sys.env("MEDIA_FOLDER_ROOT_PATH")
val mediaFolderCacheRootPath: String = sys.env("MEDIA_FOLDER_CACHE_ROOT_PATH")
}
......@@ -68,4 +68,40 @@ trait BinaryHandler {
record.setBinariesStatus(ProcessingIgnore, "No attached local binaries")
}
}
def deleteCachedBinaries(record: ProcessedRecord): ProcessedRecord = {
if (record.binaries.nonEmpty) {
val result = record.binaries
.map(_.replaceFirst("file://", ""))
.map(_.replaceFirst(mediaFolderRootPath, mediaFolderCacheRootPath))
.map(fileName => (new File(fileName), fileName))
.map(file =>
(if (record.dryRun) file._1.exists else file._1.delete, file._2)
)
.foldLeft[List[String]](List())((errors, x) =>
if (!x._1) {
logger.info(s"No thumbnail ${x._2} exists${if (record.dryRun) " (dry-run mode)" else ""}!")
errors :+ s"Deletion of thumbnail ${x._2} failed (probably because there are no cached thumbnails...)"
} else {
errors
}
)
if (result.isEmpty) {
logger.info(
s"Deletion of cached thumbnails for record ${record.recordId} successful${if (record.dryRun) " (dry-run mode)" else ""}"
)
record.setBinariesStatus(
ProcessingSuccess,
"Cached thumbnails deletion successful"
)
} else {
logger.info(
s"Thumbnail ${record.recordId} not available${if (record.dryRun) " (dry-run mode)" else ""}"
)
record.setBinariesStatus(ProcessingIgnore, result.mkString("; "))
}
} else {
record.setBinariesStatus(ProcessingIgnore, "No attached local binaries")
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment