فهرست منبع

#2300 modify exception handling

Shinsuke Sugaya 5 سال پیش
والد
کامیت
0c1b24dc57

+ 12 - 5
src/main/java/org/codelibs/fess/job/CrawlJob.java

@@ -159,6 +159,8 @@ public class CrawlJob extends ExecJob {
         try {
         try {
             executeCrawler();
             executeCrawler();
             ComponentUtil.getKeyMatchHelper().update();
             ComponentUtil.getKeyMatchHelper().update();
+        } catch (final JobProcessingException e) {
+            throw e;
         } catch (final Exception e) {
         } catch (final Exception e) {
             throw new JobProcessingException("Failed to execute a crawl job.", e);
             throw new JobProcessingException("Failed to execute a crawl job.", e);
         } finally {
         } finally {
@@ -338,7 +340,7 @@ public class CrawlJob extends ExecJob {
             final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
             final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
 
 
             if (logger.isInfoEnabled()) {
             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 -> {
             final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> {
@@ -356,13 +358,18 @@ public class CrawlJob extends ExecJob {
             final int exitValue = currentProcess.exitValue();
             final int exitValue = currentProcess.exitValue();
 
 
             if (logger.isInfoEnabled()) {
             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) {
             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) {
         } catch (final Exception e) {
             throw new JobProcessingException("Crawler Process terminated.", e);
             throw new JobProcessingException("Crawler Process terminated.", e);
         } finally {
         } finally {

+ 4 - 1
src/main/java/org/codelibs/fess/job/ExecJob.java

@@ -47,6 +47,8 @@ public abstract class ExecJob {
 
 
     protected int timeout = -1; // sec
     protected int timeout = -1; // sec
 
 
+    protected boolean processTimeout = false;
+
     public abstract String execute();
     public abstract String execute();
 
 
     protected abstract String getExecuteType();
     protected abstract String getExecuteType();
@@ -150,8 +152,9 @@ public abstract class ExecJob {
             return null;
             return null;
         }
         }
         return TimeoutManager.getInstance().addTimeoutTarget(() -> {
         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);
             ComponentUtil.getProcessHelper().destroyProcess(sessionId);
+            processTimeout = true;
         }, timeout, false);
         }, timeout, false);
     }
     }
 }
 }

+ 10 - 5
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();
             final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
 
 
             if (logger.isInfoEnabled()) {
             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 -> {
             final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> {
@@ -239,14 +239,19 @@ public class GenerateThumbnailJob extends ExecJob {
             final int exitValue = currentProcess.exitValue();
             final int exitValue = currentProcess.exitValue();
 
 
             if (logger.isInfoEnabled()) {
             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) {
             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();
             ComponentUtil.getPopularWordHelper().clearCache();
-        } catch (final InterruptedException e) {
-            logger.warn("ThumbnailGenerator Process interrupted.");
+        } catch (final JobProcessingException e) {
+            throw e;
         } catch (final Exception e) {
         } catch (final Exception e) {
             throw new JobProcessingException("ThumbnailGenerator Process terminated.", e);
             throw new JobProcessingException("ThumbnailGenerator Process terminated.", e);
         } finally {
         } finally {

+ 10 - 5
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();
             final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
 
 
             if (logger.isInfoEnabled()) {
             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 -> {
             final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> {
@@ -221,14 +221,19 @@ public class SuggestJob extends ExecJob {
             final int exitValue = currentProcess.exitValue();
             final int exitValue = currentProcess.exitValue();
 
 
             if (logger.isInfoEnabled()) {
             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) {
             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();
             ComponentUtil.getPopularWordHelper().clearCache();
-        } catch (final InterruptedException e) {
-            logger.warn("SuggestCreator Process interrupted.");
+        } catch (final JobProcessingException e) {
+            throw e;
         } catch (final Exception e) {
         } catch (final Exception e) {
             throw new JobProcessingException("SuggestCreator Process terminated.", e);
             throw new JobProcessingException("SuggestCreator Process terminated.", e);
         } finally {
         } finally {