Schmooze:: Process failed + when using grover gem to convert html2pdf

843 Views Asked by At
respond_to do |format|
        format.html
        format.pdf do
          grover = Grover.new('http://localhost:3000/generate_report', format: 'A4')
          pdf = grover.to_pdf
          File.open(Rails.root.join('report.pdf'),'wb', encoding: 'ascii-8bit') { |f| f.write(pdf)}

        end
      end

I need to convert my html page to pdf. But i get a "schmooze process fail" and the system hangs when it does grover.to_pdf. It works well on terminal but not in my rails project.

1

There are 1 best solutions below

1
Unixmonkey On

It sounds like your system is hanging because when you run Rails in development mode by default, you are only running with 1 thread.

When you are inside of your request, and attempt to hit the generate_report endpoint, you are queuing the request and waiting for it's response, however because Rails can only serve one request at a time, the response never comes, so the request never finishes, causing a deadlock.

Try to get the HTML for the report without making a web request, by populating a template or calling ActionController.render() and using that instead.

If that's not an option for you, configure your Rails server to use multiple threads in development mode (I recommend you use Puma in dev mode, or whatever production uses).