Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry opening output_file if it fails #30

Merged
merged 1 commit into from
Feb 8, 2015

Conversation

msabramo
Copy link
Contributor

@msabramo msabramo commented Feb 2, 2015

Hoping that this fixes intermittent 500 errors due to inability to open temp files, as seen in #28.

Or maybe at least gives us more info about whether this is the problem.

I tested this by adding a bit of code to simulate a temporary problem opening a file:

      while num_tries < max_retries
        begin
          File.open(output_file) do |f|
            @output = f.read
          end
          num_tries += 1
          if num_tries < 3 then
            File.open("some_file_that_doesnt_exist.txt") do |f|
              @output = f.read
            end
          end
          break
        rescue
          puts "Failed to open #{output_file}; num_tries = #{num_tries}"
          sleep 0.020
        end
      end

Result of running this and hitting it with HTTPie:

$ foreman start
file:/Users/marca/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/kernel19/process.rb:4 warning: unsupported spawn option: err
file:/Users/marca/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/kernel19/process.rb:4 warning: unsupported spawn option: out
15:02:10 web.1  | started with pid 68484
Mizuno 0.6.6 (Jetty 8.1.3.v20120416) listening on 0.0.0.0:5000
["pandoc", "--standalone", "--output=output.a6f8e0c2b17d45e2999d.rst", "--from=markdown", "--to=rst", "tmpqBtaRr"]
"pandoc --standalone --output\\=output.a6f8e0c2b17d45e2999d.rst --from\\=markdown --to\\=rst tmpqBtaRr 2>&1"
Failed to open output.a6f8e0c2b17d45e2999d.rst; num_tries = 1
Failed to open output.a6f8e0c2b17d45e2999d.rst; num_tries = 2
127.0.0.1 - - [02/Feb/2015 15:07:05] "POST /convert HTTP/1.1" 200 - 0.3130
$ http --form -f POST http://localhost:5000/convert from=markdown to=rst 'input_files[]@/tmp/tmpqBtaRr'
HTTP/1.1 200 OK
Content-Length: 61
Content-Type: application/octet-stream
X-Content-Type-Options: nosniff

pydocverter
===========

Python client for Docverter service

So it failed to open the file twice and then it succeeded on the 3rd try and everything works.

Hoping that this fixes intermittent 500 errors due to inability to open
temp files, as seen in Docverter#28.
@msabramo msabramo mentioned this pull request Feb 2, 2015
peterkeen added a commit that referenced this pull request Feb 8, 2015
Retry opening output_file if it fails
@peterkeen peterkeen merged commit eddde56 into Docverter:master Feb 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants