Skip to content

Commit

Permalink
Copy and cleanup for dropbox
Browse files Browse the repository at this point in the history
  • Loading branch information
sven1103 committed Jun 3, 2024
1 parent f96ccb9 commit 8f740f1
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import life.qbic.data.processing.Provenance;
import life.qbic.data.processing.Provenance.ProvenanceException;
import life.qbic.data.processing.config.RoundRobinDraw;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;

/**
Expand Down Expand Up @@ -151,13 +152,25 @@ private void evaluateDirectory(File taskDir) {
LOG.error("Could not update provenance file: {}", taskDir.getAbsolutePath(), e);
moveToSystemIntervention(taskDir, e.getMessage());
}
moveToTargetDir(taskDir);
try {
copyToTargetDir(taskDir);
} catch (IOException e) {
LOG.error("Could not copy to target directory: {}", taskDir.getAbsolutePath(), e);
moveToSystemIntervention(taskDir,
"Cannot copy task to target directory: %s".formatted(assignedTargetDirectory));
}
try {
createMarkerFile(assignedTargetDirectory, taskDir.getName());
} catch (IOException e) {
LOG.error("Could not create marker file in: {}", assignedTargetDirectory, e);
moveToSystemIntervention(taskDir, e.getMessage());
}
try {
cleanup(taskDir);
} catch (IOException e) {
LOG.error("Could not clean up task directory: {}", taskDir.getAbsolutePath(), e);
moveToSystemIntervention(taskDir, e.getMessage());
}
return;
}
var errorMessage = ErrorSummary.createSimple(taskDir.getName(),
Expand All @@ -170,6 +183,11 @@ private void evaluateDirectory(File taskDir) {
moveBackToOrigin(taskDir, provenance, errorMessage.toString());
}

private void cleanup(File taskDir) throws IOException {
LOG.info("Deleting task directory: {}", taskDir.getAbsolutePath());
FileUtils.deleteDirectory(taskDir);
}

private void updateProvenanceFile(File provenanceFile, Provenance provenance) throws IOException {
var mapper = new ObjectMapper();
mapper.writerWithDefaultPrettyPrinter().writeValue(provenanceFile, provenance);
Expand Down Expand Up @@ -209,18 +227,11 @@ private void moveBackToOrigin(File taskDir, Provenance provenance, String reason
}
}

private void moveToTargetDir(File taskDir) {
private void copyToTargetDir(File taskDir) throws IOException {
LOG.info(
"Moving %s to target directory %s".formatted(taskDir.getAbsolutePath(),
"Copying %s to target directory %s".formatted(taskDir.getAbsolutePath(),
assignedTargetDirectory));
try {
Files.move(taskDir.toPath(), assignedTargetDirectory.resolve(taskDir.getName()));
} catch (IOException e) {
LOG.error("Cannot move task to target directory: %s".formatted(assignedTargetDirectory), e);
moveToSystemIntervention(taskDir,
"Cannot move task to target directory: %s".formatted(assignedTargetDirectory));
}

FileUtils.copyDirectory(taskDir, assignedTargetDirectory.resolve(taskDir.getName()).toFile());
}

private List<File> tasks() {
Expand Down

0 comments on commit 8f740f1

Please sign in to comment.