Skip to content

Commit

Permalink
Don't issue delete statement unless there's something to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed Sep 10, 2024
1 parent 72bca05 commit 4b31e5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ReleasedDataModel(
) {
@Transactional(readOnly = true)
fun getReleasedData(organism: Organism): Sequence<ProcessedData<GeneticSequence>> {
log.info { "fetching released submissions" }
log.info { "Fetching released submissions from database for organism $organism" }

val latestVersions = submissionDatabaseService.getLatestVersions(organism)
val latestRevocationVersions = submissionDatabaseService.getLatestRevocationVersions(organism)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SubmissionDatabaseService(
organism: Organism,
pipelineVersion: Long,
): Sequence<UnprocessedData> {
log.info { "streaming unprocessed submissions. Requested $numberOfSequenceEntries sequence entries." }
log.info { "Request received to stream up to $numberOfSequenceEntries unprocessed submissions for $organism." }

return fetchUnprocessedEntriesAndUpdateToInProcessing(
organism,
Expand Down Expand Up @@ -981,16 +981,36 @@ class SubmissionDatabaseService(

fun cleanUpStaleSequencesInProcessing(timeToStaleInSeconds: Long) {
val staleDateTime = Instant.fromEpochMilliseconds(
Clock.System.now().toEpochMilliseconds() - timeToStaleInSeconds * 1000,
Clock.System.now().toEpochMilliseconds() - timeToStaleInSeconds * 1000
).toLocalDateTime(TimeZone.UTC)

val numberDeleted = SequenceEntriesPreprocessedDataTable.deleteWhere {
statusIs(IN_PROCESSING) and startedProcessingAtColumn.less(staleDateTime)
transaction {
// Check if there are any stale sequences before attempting to delete
// Check if there are any stale sequences before issuing a delete
val staleSequencesExist = SequenceEntriesPreprocessedDataTable
.selectAll()
.where {
SequenceEntriesPreprocessedDataTable.statusIs(PreprocessingStatus.IN_PROCESSING) and
(SequenceEntriesPreprocessedDataTable.startedProcessingAtColumn.less(staleDateTime))
}
.limit(1)
.empty()
.not()


if (staleSequencesExist) {
val numberDeleted = SequenceEntriesPreprocessedDataTable.deleteWhere {
statusIs(IN_PROCESSING) and startedProcessingAtColumn.less(staleDateTime)
}
log.info { "Cleaned up $numberDeleted stale sequences in processing" }
} else {
log.info { "No stale sequences found for cleanup" }
}
}
log.info { "Cleaning up $numberDeleted stale sequences in processing" }
}

fun useNewerProcessingPipelineIfPossible(): Long? {
log.info("Checking for newer processing pipeline versions")
val sql = """
update current_processing_pipeline
set
Expand Down

0 comments on commit 4b31e5b

Please sign in to comment.