diff --git a/backend/src/main/java/com/printcalculator/service/SlicerService.java b/backend/src/main/java/com/printcalculator/service/SlicerService.java index 5d08dd7..e2fe18b 100644 --- a/backend/src/main/java/com/printcalculator/service/SlicerService.java +++ b/backend/src/main/java/com/printcalculator/service/SlicerService.java @@ -85,22 +85,7 @@ public class SlicerService { logger.info("Executing Slicer: " + String.join(" ", command)); - ProcessBuilder pb = new ProcessBuilder(command); - pb.directory(tempDir.toFile()); - pb.environment().put("HOME", "/tmp"); - pb.environment().put("QT_QPA_PLATFORM", "offscreen"); - - Process process = pb.start(); - if (!process.waitFor(5, TimeUnit.MINUTES)) { - process.destroy(); - throw new IOException("Slicer timeout"); - } - - if (process.exitValue() != 0) { - String out = new String(process.getInputStream().readAllBytes()); - String err = new String(process.getErrorStream().readAllBytes()); - throw new IOException("Slicer failed with exit code " + process.exitValue() + "\nERR: " + err + "\nOUT: " + out); - } + runSlicerCommand(command, tempDir); // Find any .gcode file try (Stream s = Files.list(tempDir)) { @@ -114,4 +99,23 @@ public class SlicerService { throw new IOException(e); } } + + protected void runSlicerCommand(List command, Path tempDir) throws IOException, InterruptedException { + ProcessBuilder pb = new ProcessBuilder(command); + pb.directory(tempDir.toFile()); + pb.environment().put("HOME", "/tmp"); + pb.environment().put("QT_QPA_PLATFORM", "offscreen"); + + Process process = pb.start(); + if (!process.waitFor(5, TimeUnit.MINUTES)) { + process.destroy(); + throw new IOException("Slicer timeout"); + } + + if (process.exitValue() != 0) { + String out = new String(process.getInputStream().readAllBytes()); + String err = new String(process.getErrorStream().readAllBytes()); + throw new IOException("Slicer failed with exit code " + process.exitValue() + "\nERR: " + err + "\nOUT: " + out); + } + } } diff --git a/backend/src/test/java/com/printcalculator/service/SlicerServiceTest.java b/backend/src/test/java/com/printcalculator/service/SlicerServiceTest.java index 11b2db6..4514ecd 100644 --- a/backend/src/test/java/com/printcalculator/service/SlicerServiceTest.java +++ b/backend/src/test/java/com/printcalculator/service/SlicerServiceTest.java @@ -49,7 +49,7 @@ class SlicerServiceTest { // Subclass to override runSlicerCommand slicerService = new SlicerService("orca-slicer", profileManager, gCodeParser, mapper) { @Override - protected void runSlicerCommand(List command, Path tempDir) throws IOException { + protected void runSlicerCommand(List command, Path tempDir) throws IOException, InterruptedException { lastCommand = command; lastTempDir = tempDir; // Don't run actual process.