Skip to content
Snippets Groups Projects
Commit 8a1d5ba8 authored by Gustavo Trott's avatar Gustavo Trott
Browse files

Handle and log timeout error during Office2Pdf conversion

parent 64d3afbb
No related branches found
No related tags found
No related merge requests found
...@@ -59,18 +59,22 @@ public abstract class Office2PdfPageConverter { ...@@ -59,18 +59,22 @@ public abstract class Office2PdfPageConverter {
log.info(String.format("Calling conversion script %s.", presOfficeConversionExec)); log.info(String.format("Calling conversion script %s.", presOfficeConversionExec));
NuProcessBuilder officeConverterExec = new NuProcessBuilder(Arrays.asList(presOfficeConversionExec, presentationFile.getAbsolutePath(), output.getAbsolutePath())); NuProcessBuilder officeConverterExec = new NuProcessBuilder(Arrays.asList("timeout", conversionTimeout + "s", "/bin/sh", "-c",
"\""+presOfficeConversionExec + "\" \"" + presentationFile.getAbsolutePath() + "\" \"" + output.getAbsolutePath()+"\""));
Office2PdfConverterHandler office2PdfConverterHandler = new Office2PdfConverterHandler(); Office2PdfConverterHandler office2PdfConverterHandler = new Office2PdfConverterHandler();
officeConverterExec.setProcessListener(office2PdfConverterHandler); officeConverterExec.setProcessListener(office2PdfConverterHandler);
NuProcess process = officeConverterExec.start(); NuProcess process = officeConverterExec.start();
try { try {
process.waitFor(conversionTimeout, TimeUnit.SECONDS); process.waitFor(conversionTimeout + 1, TimeUnit.SECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("InterruptedException while counting PDF pages {}", presentationFile.getName(), e); log.error("InterruptedException while counting PDF pages {}", presentationFile.getName(), e);
} }
if(office2PdfConverterHandler.isCommandTimeout()) {
log.error("Command execution ({}) exceeded the {} secs timeout for {}.",presOfficeConversionExec, conversionTimeout, presentationFile.getName());
}
if(!office2PdfConverterHandler.isCommandSuccessful()) { if(!office2PdfConverterHandler.isCommandSuccessful()) {
throw new Exception(String.format("Error while executing conversion script %s.", presOfficeConversionExec)); throw new Exception(String.format("Error while executing conversion script %s.", presOfficeConversionExec));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment