Faking a Streaming Response in Django to Avoid Heroku Timeout

Viewed 728

I have a Django app that uses django-wkhtmltopdf to generate PDFs on Heroku. Some of the responses exceed the 30 second timeout. Because this is a proof-of-concept running on the free tier, I'd prefer not to tear apart what I have to move to a worker/ poll process. My current view looks like this:

def dispatch(self, request, *args, **kwargs):
    do_custom_stuff()
    return super(MyViewClass, self).dispatch(request, *args, **kwargs)

Is there a way I can override the dispatch method of the view class to fake a streaming response like this or with the Empy Chunking approach mentioned here to send an empty response until the PDF is rendered? Sending an empty byte will restart the timeout process giving plenty of time to send the PDF.

1 Answers
Related