Jeff
Jeff

Reputation: 11

Generating PDF's via Delayed Job while maintaing a RESTful pattern

currently I am running a Rails app on Heroku, and everything is working great with exception of generating PDF documents that sometimes contain thousands of records. Heroku has a built-in timeout of 30 seconds, so if the request takes more than 30 seconds, it's abandoned.

That's fine, since they offer delayed_job support built-in. However, all of the PDF's i generate follow a typical restful pattern. For instance, a request to "/posts.pdf" generates a pdf (using PRAWN and PRAWNTO) and it's delivered to the browser.

So my basic question is, how do I create dynamically generated PDF's with delayed_job while maintaining the basic RESTful patterns Rail's so conveniently provides. Thanks.

Upvotes: 1

Views: 566

Answers (1)

Ryan Angilly
Ryan Angilly

Reputation: 1647

You could do something like:

  1. Send a request to generate the pdf: POST /generate_new_pdf
  2. Have that action return the ID of the new pdf before it's created
  3. Poll the endpoint for that resource ID until it's done (returning 202's in the meantime): GET /pdfs/:id

Upvotes: 2

Related Questions