diff --git a/src/main/java/org/codelibs/fess/job/CrawlJob.java b/src/main/java/org/codelibs/fess/job/CrawlJob.java index e2f308ffb..cc1fbb433 100644 --- a/src/main/java/org/codelibs/fess/job/CrawlJob.java +++ b/src/main/java/org/codelibs/fess/job/CrawlJob.java @@ -159,6 +159,8 @@ public class CrawlJob extends ExecJob { try { executeCrawler(); ComponentUtil.getKeyMatchHelper().update(); + } catch (final JobProcessingException e) { + throw e; } catch (final Exception e) { throw new JobProcessingException("Failed to execute a crawl job.", e); } finally { @@ -338,7 +340,7 @@ public class CrawlJob extends ExecJob { final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile(); if (logger.isInfoEnabled()) { - logger.info("Crawler: \nDirectory=" + baseDir + "\nOptions=" + cmdList); + logger.info("Crawler: \nDirectory={}\nOptions={}", baseDir, cmdList); } final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> { @@ -356,13 +358,18 @@ public class CrawlJob extends ExecJob { final int exitValue = currentProcess.exitValue(); if (logger.isInfoEnabled()) { - logger.info("Crawler: Exit Code=" + exitValue + " - Crawler Process Output:\n" + it.getOutput()); + logger.info("Crawler: Exit Code={} - Process Output:\n{}", exitValue, it.getOutput()); } if (exitValue != 0) { - throw new JobProcessingException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput()); + final StringBuilder out = new StringBuilder(); + if (processTimeout) { + out.append("Process is terminated due to ").append(timeout).append(" second exceeded.\n"); + } + out.append("Exit Code: ").append(exitValue).append("\nOutput:\n").append(it.getOutput()); + throw new JobProcessingException(out.toString()); } - } catch (final InterruptedException e) { - logger.warn("Crawler Process interrupted."); + } catch (final JobProcessingException e) { + throw e; } catch (final Exception e) { throw new JobProcessingException("Crawler Process terminated.", e); } finally { diff --git a/src/main/java/org/codelibs/fess/job/ExecJob.java b/src/main/java/org/codelibs/fess/job/ExecJob.java index bb8acf121..e7fe9a086 100644 --- a/src/main/java/org/codelibs/fess/job/ExecJob.java +++ b/src/main/java/org/codelibs/fess/job/ExecJob.java @@ -47,6 +47,8 @@ public abstract class ExecJob { protected int timeout = -1; // sec + protected boolean processTimeout = false; + public abstract String execute(); protected abstract String getExecuteType(); @@ -150,8 +152,9 @@ public abstract class ExecJob { return null; } return TimeoutManager.getInstance().addTimeoutTarget(() -> { - logger.warn("Process is terminated due to {}ms exceeded.", timeout); + logger.warn("Process is terminated due to {} second exceeded.", timeout); ComponentUtil.getProcessHelper().destroyProcess(sessionId); + processTimeout = true; }, timeout, false); } } \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/job/GenerateThumbnailJob.java b/src/main/java/org/codelibs/fess/job/GenerateThumbnailJob.java index 63d8e7612..f41955034 100644 --- a/src/main/java/org/codelibs/fess/job/GenerateThumbnailJob.java +++ b/src/main/java/org/codelibs/fess/job/GenerateThumbnailJob.java @@ -221,7 +221,7 @@ public class GenerateThumbnailJob extends ExecJob { final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile(); if (logger.isInfoEnabled()) { - logger.info("ThumbnailGenerator: \nDirectory=" + baseDir + "\nOptions=" + cmdList); + logger.info("ThumbnailGenerator: \nDirectory={}\nOptions={}", baseDir, cmdList); } final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> { @@ -239,14 +239,19 @@ public class GenerateThumbnailJob extends ExecJob { final int exitValue = currentProcess.exitValue(); if (logger.isInfoEnabled()) { - logger.info("ThumbnailGenerator: Exit Code=" + exitValue + " - ThumbnailGenerator Process Output:\n" + it.getOutput()); + logger.info("ThumbnailGenerator: Exit Code={} - Process Output:\n{}", exitValue, it.getOutput()); } if (exitValue != 0) { - throw new JobProcessingException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput()); + final StringBuilder out = new StringBuilder(); + if (processTimeout) { + out.append("Process is terminated due to ").append(timeout).append(" second exceeded.\n"); + } + out.append("Exit Code: ").append(exitValue).append("\nOutput:\n").append(it.getOutput()); + throw new JobProcessingException(out.toString()); } ComponentUtil.getPopularWordHelper().clearCache(); - } catch (final InterruptedException e) { - logger.warn("ThumbnailGenerator Process interrupted."); + } catch (final JobProcessingException e) { + throw e; } catch (final Exception e) { throw new JobProcessingException("ThumbnailGenerator Process terminated.", e); } finally { diff --git a/src/main/java/org/codelibs/fess/job/SuggestJob.java b/src/main/java/org/codelibs/fess/job/SuggestJob.java index 5d5c225e4..89aaa8c48 100644 --- a/src/main/java/org/codelibs/fess/job/SuggestJob.java +++ b/src/main/java/org/codelibs/fess/job/SuggestJob.java @@ -203,7 +203,7 @@ public class SuggestJob extends ExecJob { final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile(); if (logger.isInfoEnabled()) { - logger.info("SuggestCreator: \nDirectory=" + baseDir + "\nOptions=" + cmdList); + logger.info("SuggestCreator: \nDirectory={}\nOptions={}", baseDir, cmdList); } final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> { @@ -221,14 +221,19 @@ public class SuggestJob extends ExecJob { final int exitValue = currentProcess.exitValue(); if (logger.isInfoEnabled()) { - logger.info("SuggestCreator: Exit Code=" + exitValue + " - SuggestCreator Process Output:\n" + it.getOutput()); + logger.info("SuggestCreator: Exit Code={} - Process Output:\n{}", exitValue, it.getOutput()); } if (exitValue != 0) { - throw new JobProcessingException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput()); + final StringBuilder out = new StringBuilder(); + if (processTimeout) { + out.append("Process is terminated due to ").append(timeout).append(" second exceeded.\n"); + } + out.append("Exit Code: ").append(exitValue).append("\nOutput:\n").append(it.getOutput()); + throw new JobProcessingException(out.toString()); } ComponentUtil.getPopularWordHelper().clearCache(); - } catch (final InterruptedException e) { - logger.warn("SuggestCreator Process interrupted."); + } catch (final JobProcessingException e) { + throw e; } catch (final Exception e) { throw new JobProcessingException("SuggestCreator Process terminated.", e); } finally {