Skip to content

Commit

Permalink
Retry opening output_file if it fails
Browse files Browse the repository at this point in the history
Hoping that this fixes intermittent 500 errors due to inability to open
temp files, as seen in Docverter#28.
  • Loading branch information
msabramo committed Feb 2, 2015
1 parent 1f8eb8a commit 9c7e0fb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/docverter-server/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ 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
num_tries += 1
break
rescue
puts "Failed to open #{output_file}; num_tries = #{num_tries}"
sleep 0.020
end
end

@output
end

Expand Down

0 comments on commit 9c7e0fb

Please sign in to comment.