From d60306f8f8dfb850bcbdb5f0b17acfdacd3864e6 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Mon, 2 Feb 2015 14:31:18 -0800 Subject: [PATCH] Retry opening output_file if it fails Hoping that this fixes intermittent 500 errors due to inability to open temp files, as seen in #28. --- lib/docverter-server/app.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/docverter-server/app.rb b/lib/docverter-server/app.rb index b831142..2a225a2 100644 --- a/lib/docverter-server/app.rb +++ b/lib/docverter-server/app.rb @@ -40,10 +40,22 @@ class DocverterServer::App < Sinatra::Base content_type(DocverterServer::ConversionTypes.mime_type(manifest['to'])) + num_tries = 0 + max_retries = 10 @output = nil - File.open(output_file) do |f| - @output = f.read + + while num_tries < max_retries + begin + File.open(output_file) do |f| + @output = f.read + end + break + raise + puts "Failed to open #{output_file}" + sleep 0.020 + end end + @output end