Skip to content

Commit

Permalink
feat: add generation process error stream to debug log (#220)
Browse files Browse the repository at this point in the history
This adds the generation process error stream to debug log since otherwise there's a possibility that the buffer gets filled up and blocks the generation process.

Related to #184
  • Loading branch information
SudharakaP authored Aug 16, 2020
1 parent 35ea2b3 commit 354d85e
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void addCiCd(String generationId, File workingDir, CiCdTool ciCdTool) thr
private void runProcess(String generationId, File workingDir, String command) throws IOException {
log.info("Running command: \"{}\" in directory: \"{}\"", command, workingDir);
BufferedReader input = null;
BufferedReader error = null;
try {
String line;
Process p = Runtime.getRuntime().exec
Expand All @@ -94,28 +95,37 @@ private void runProcess(String generationId, File workingDir, String command) th
taskExecutor.execute(() -> {
try {
p.waitFor(timeout, TimeUnit.SECONDS);
if (p.isAlive()) {
p.destroyForcibly();
}
p.destroyForcibly();
} catch (InterruptedException e) {
log.error("Unable to execute process successfully.", e);
Thread.currentThread().interrupt();
}
});

error = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
while ((line = error.readLine()) != null) {
log.debug(line);
}

input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while (input.ready() && (line = input.readLine()) != null) {
while ((line = input.readLine()) != null) {
log.debug(line);
this.logsService.addLog(generationId, line);
}

input.close();
error.close();
} catch (Exception e) {
log.error("Error while running the process", e);
if (input != null) {
input.close();
}
if (error != null) {
error.close();
}
throw e;
}
}
Expand Down

0 comments on commit 354d85e

Please sign in to comment.