Skip to content

Commit

Permalink
analysis: improve last execution steps, #TASK-6445
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Sep 30, 2024
1 parent 2e91ab4 commit ab8086a
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -295,35 +296,46 @@ protected void run() throws Exception {
StopWatch stopWatch = StopWatch.createStarted();
DockerUtils.run(dockerImage, inputBindings, outputBinding, stringBuilder.toString(), dockerParams);
logger.info("Execution time: " + TimeUtils.durationToString(stopWatch));
}

@Override
protected void finalize() throws Throwable {
super.finalize();
}

@Override
protected void onShutdown() {
endTraceFileMonitor();
deleteTemporalFiles();
}

private void deleteTemporalFiles() {
// Delete input files and temporal directory
try (Stream<Path> paths = Files.walk(temporalInputDir)) {
paths.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(java.io.File::delete);
} catch (IOException e) {
logger.error("Could not delete temporal input directory: " + temporalInputDir, e);
}

// Delete temporal files and folders created by nextflow
try (Stream<Path> paths = Files.walk(getOutDir().resolve(".nextflow"))) {
paths.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(java.io.File::delete);
} catch (IOException e) {
logger.error("Could not delete temporal nextflow directory: " + getOutDir().resolve(".nextflow"), e);
}
try (Stream<Path> paths = Files.walk(getOutDir().resolve("work"))) {
paths.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(java.io.File::delete);
} catch (IOException e) {
logger.error("Could not delete temporal work directory: " + getOutDir().resolve("work"), e);
}

}

@Override
protected void onShutdown() {
super.onShutdown();
endTraceFileMonitor();
}

protected void endTraceFileMonitor() {
if (thread != null) {
thread.interrupt();
Expand Down

0 comments on commit ab8086a

Please sign in to comment.