#2300 modify exception handling

This commit is contained in:
Shinsuke Sugaya 2019-11-12 22:44:50 +09:00
parent 0e3e137cf2
commit 0c1b24dc57
4 changed files with 36 additions and 16 deletions

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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 {

View file

@ -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 {