From ce36ba9fe90ec5dec7866920430bf5d58d76eb74 Mon Sep 17 00:00:00 2001 From: straightupjac Date: Mon, 30 Jan 2023 15:29:35 -0500 Subject: [PATCH] feat: update scripts to delete jobs after processing --- .../ca/uwaterloo/cs489/exercise2/MainApp.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java b/java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java index c699133..e2344fb 100644 --- a/java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java +++ b/java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java @@ -3,7 +3,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; -import java.io.FileNotFoundException; +import java.io.File; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -13,7 +13,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - public class MainApp { private static Path getDirectory() throws IOException { @@ -30,11 +29,24 @@ public static void main(String[] args) { try { Path dir = getDirectory(); DirectoryStream ds = Files.newDirectoryStream(dir); + logger.info(String.format("Looking at jobs in directory %s\n", dir)); // Iterate over all of the files in the directory, creating a job for each for (Path entry : ds) { - Job job = new Job(entry.toFile()); - logger.info(String.format("Job %d yields %d\n", job.getInput(), job.processJob())); + File jobFile = entry.toFile(); + Job job = new Job(jobFile); + int processJob = job.processJob(); + + logger.info(String.format("Job %d yields %d\n", job.getInput(), processJob)); + jobFile.delete(); + logger.info(String.format("Deleted job %d\n", job.getInput())); + } + File jobsDir = new File(dir.toUri()); + if (jobsDir.delete()) { + logger.info(String.format("Deleted job directory: %s\n", jobsDir.getName())); + } else { + System.out.println("Failed to delete the folder."); + logger.info(String.format("Failed to delete the jobs directory: %s\n", jobsDir.getName())); } } catch (IOException e) { e.printStackTrace();