Skip to content

Commit

Permalink
Merge pull request #1324 from libris/feature/whelktool-exit-on-error
Browse files Browse the repository at this point in the history
Terminate script immediately (with explicit exit code) on error
  • Loading branch information
kwahlin authored Nov 8, 2023
2 parents 63fbe8c + f42d44f commit 4935836
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions whelktool/src/main/groovy/datatool/WhelkTool.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,7 @@ class WhelkTool {
}

private void select(Iterable<Document> selection, Closure process,
int batchSize = DEFAULT_BATCH_SIZE, boolean newItems = false) {
if (errorDetected) {
log "Error detected, refusing further processing."
return
}

int batchSize = DEFAULT_BATCH_SIZE, boolean newItems = false) throws Exception {
int batchCount = 0
Batch batch = new Batch(number: ++batchCount)

Expand All @@ -303,6 +298,7 @@ class WhelkTool {
err.printStackTrace errorLog
errorLog.println "-" * 20
errorLog.flush()
errorDetected = err
}
}

Expand Down Expand Up @@ -351,6 +347,11 @@ class WhelkTool {
log()
}
loggerFuture?.cancel(true)

if (errorDetected) {
log "Error detected, refusing further processing."
throw new Exception()
}
}

private def createExecutorService() {
Expand Down Expand Up @@ -676,9 +677,12 @@ class WhelkTool {
log()

bindings = createMainBindings()
script.eval(bindings)

finish()
try {
script.eval(bindings)
} finally {
finish()
}
}

private void finish() {
Expand All @@ -687,6 +691,10 @@ class WhelkTool {
it.flush()
it.close()
}
if (errorDetected) {
log "Script terminated due to an error, see $reportsDir/ERRORS.txt for more info"
System.exit(1)
}
log "Done!"
}

Expand Down

0 comments on commit 4935836

Please sign in to comment.