24 3 / 2011
Got my first commit on a open source project this week:
06 1 / 2011
PDFKit and its middleware on Heroku
I run into this problem with PDFKit middleware where the PDF generation seems to hang indefinitely for no apparent reason on Heroku as well as locally when using Thin.
Wkhtmltopdf will load the HTML and then try to load all assets from it (js, css, images, etc.) On Heroku the asset is first served up by the rails server and when you have a single Dyno it will create a deadlock in the handling of the HTTP request. The user trying to access the pdf document will consume the Dynos and the PDF generator will wait for it. Deadlock.
Two ways around that:
- Access the static files directly from the web server and not Rails
- Access the static files locally
The first option requires some setup (cloudfront and such) and some actions at deployment. Overall this requires to much work.
The second option is the one I preferred. I used Rails asset_host to have all assets for a PDF generation fetch locally (file://). Here is the gist of it:
Works as intended! Hope this will save some people the time I spent on this.
(Note: You first have to follow Matt’s instructions on how to install wkhtmltopdf on Heroku )
Permalink 13 notes
16 11 / 2010
I just created a new repo on Github called template-fetch. The goal of those 60 lines of code is simple: retrieve an haml template from the server and process it on the client side using HAML (for now). I plan to add other templating engines when I have more time.
It uses jQuery, underscore.js and haml.js to do its magic.
It is mostly inspired from Sammy and was built when I was tinkering with Backbone.js . I think it can be useful to other, you tell me!
Comment are always welcome.
21 10 / 2010