I'm running a rails app, which has a json webservice call from a local client developed in c++ (a post command with a multipart json form, uploading a streamed file)
I already read on Heroku docs about routing mesh, mentioning the 30s Heroku limit for http connections, and about the long polling alternative, referring to worker dynos.
During my call I process pdf documents and insert a signature into them. This pdf documents can either be 100kb or 11Mb (or perhaps more).
I understand that I'll eventually have to do this action on a background process, but I would like to avoid doing it before I absolutely have to.
Do you know of any way of increasing this timeout?
As you may see in my code below, I am processing my document after it gets saved (I was doing this inside an after_save
, but changed to the controller hoping to send the response before processing).
I would so expect that the client would get a response before the document processing, but I'm still having a timeout on the heroku side, and an error on my client side.
This all works fine with smaller documents, but for a 121 pages pdf document with only 400kb, it blows off..
In the end, my file gets uploaded, so all I need is for that response to proceed to my client app before the timeout response is sent...
Any suggestions?
my error:
at=error code=H12 desc="Request timeout" method=POST path=/documents host=fierce-beach-2720.herokuapp.com fwd="81.193.155.217/bl4-155-217.dsl.telepac.pt" dyno=web.1 queue=0ms wait=0ms connect=1ms service=32272ms status=503 bytes=0
my controller :
respond_to do |format|
if @document.save!
format.html { redirect_to root_path, :flash => { :success => 'Document was successfully created.'} }
format.json { render json: @document, status: :created, location: @document}
@document.document_process
I've ended using delayed job + workless, and now my worker dynos only run when they need to.
As heroku has the free 750 hours free per app plan, when you have low usage, you might be able to keep using it for free.
the suggestion is: use a background process!
i read that you want to avoid it, but there is no way around it! it is a best practice in web-apps to return to the client as fast as possible, because it frees up resources. when you have just one dyno running at heroku and you have multiple requests, they will get blocked for your timeout and no user is able to access your page. you can easily have denial of service cases when you have such longrunning processes.
in case you do not want to do background processes because of the cost, have a look at freemium: https://github.com/phoet/freemium
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With