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

点点圈 提交于 2020-03-25 19:28:01

问题


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:


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).



来源:https://stackoverflow.com/questions/60747083/schmooze-process-failed-when-using-grover-gem-to-convert-html2pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!