Skip to content

Commit

Permalink
analysis: improve cleaning resources step, #TASK-6445
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Sep 30, 2024
1 parent ab8086a commit be54d85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public final ExecutionResult start() throws ToolException {
logException(exception);
privateLogger.info("------- Tool '" + getId() + "' executed in "
+ TimeUtils.durationToString(result.getEnd().getTime() - result.getStart().getTime()) + " -------");
close();
}
return result;
}
Expand Down Expand Up @@ -341,6 +342,12 @@ protected void check() throws Exception {
*/
protected abstract void run() throws Exception;

/**
* Method that may be overrided by subclasses to clean up resources.
*/
protected void close() {
}

/**
* Method to be called by the Runtime shutdownHook in case of an unexpected system shutdown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected void check() throws Exception {
} else if (workflowVariable.isOutput()) {
processOutputCli("", inputFileUtils, cliParamsBuilder);
} else if (workflowVariable.isRequired() && workflowVariable.getType() != WorkflowVariable.WorkflowType.FLAG) {
throw new ToolException("Missing value for mandatory parameter: " + variableId);
throw new ToolException("Missing value for mandatory parameter: '" + variableId + "'.");
}
}
}
Expand All @@ -175,7 +175,7 @@ protected void check() throws Exception {
} else if (workflowVariable.isOutput()) {
processOutputCli("", inputFileUtils, cliParamsBuilder);
} else {
throw new ToolException("Missing mandatory parameter: " + mandatoryParam);
throw new ToolException("Missing mandatory parameter: '" + mandatoryParam + "'.");
}
}

Expand All @@ -191,7 +191,7 @@ void processInputCli(String value, InputFileUtils inputFileUtils, StringBuilder

// Write outputFile as inputBinding
inputBindings.add(new AbstractMap.SimpleEntry<>(outputFile.toString(), outputFile.toString()));
logger.info("Params: OpenCGA input file: {}", outputFile);
logger.info("Params: OpenCGA input file: '{}'", outputFile);
cliParamsBuilder.append(outputFile).append(" ");

// Add files to inputBindings to ensure they are also mounted (if any)
Expand All @@ -202,7 +202,7 @@ void processInputCli(String value, InputFileUtils inputFileUtils, StringBuilder
} else {
String path = file.getUri().getPath();
inputBindings.add(new AbstractMap.SimpleEntry<>(path, path));
logger.info("Params: OpenCGA input file: {}", path);
logger.info("Params: OpenCGA input file: '{}'", path);
cliParamsBuilder.append(path).append(" ");
}
} else {
Expand All @@ -220,7 +220,7 @@ void processOutputCli(String value, InputFileUtils inputFileUtils, StringBuilder
// If it starts directly with the subpath...
dynamicOutputFolder = inputFileUtils.appendSubpath(outDirPath, value);
}
logger.info("Params: Dynamic output folder: {}", dynamicOutputFolder);
logger.info("Params: Dynamic output folder: '{}'", dynamicOutputFolder);
cliParamsBuilder.append(dynamicOutputFolder).append(" ");
}

Expand Down Expand Up @@ -304,7 +304,7 @@ protected void finalize() throws Throwable {
}

@Override
protected void onShutdown() {
protected void close() {
endTraceFileMonitor();
deleteTemporalFiles();
}
Expand All @@ -316,22 +316,22 @@ private void deleteTemporalFiles() {
.map(Path::toFile)
.forEach(java.io.File::delete);
} catch (IOException e) {
logger.error("Could not delete temporal input directory: " + temporalInputDir, e);
logger.warn("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);
logger.warn("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);
logger.warn("Could not delete temporal work directory: " + getOutDir().resolve("work"), e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void nextflowDockerTest() throws ToolException, CatalogException, IOExcep
StopWatch stopWatch = StopWatch.createStarted();
NextFlowExecutor nextFlowExecutorTest = new NextFlowExecutor();
Map<String, String> cliParams = new HashMap<>();
cliParams.put("input", "file://samplesheet.csv");
// cliParams.put("input", "file://samplesheet.csv");
// cliParams.put("outdir", "$OUTPUT");
// cliParams.put("genome", "GRCh37");
// cliParams.put("-profile", "docker");
Expand Down

0 comments on commit be54d85

Please sign in to comment.