Skip to content

Commit

Permalink
feat: update scripts to delete jobs after processing
Browse files Browse the repository at this point in the history
  • Loading branch information
straightupjac committed Jan 30, 2023
1 parent 17edb8c commit ce36ba9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -30,11 +29,24 @@ public static void main(String[] args) {
try {
Path dir = getDirectory();
DirectoryStream<Path> 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();
Expand Down

0 comments on commit ce36ba9

Please sign in to comment.