Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Engine: correct way to start long running task in Backend from the front end?

I'd like to start a long running task on the Backend instance. This backend task will be started by the front code (servlet) via a HTTP request. This is all described in docs and it works for me.

What troubles me is that front end instances have a request duration limit of 30s (or is it 60s now?). During that request, the front end will call the backend to start the long running task. However since this task is long running and front end is waiting for it to finish and will timeout.

The question is how to make a HTTP request from front end to start the long-running backend task, so that the front end will not get a timeout and backend will continue running?

What I already tried is:

  1. Start a separate thread in the backend. My IDE (Idea) complains about this, saying that Thread are not allowed on App Engine. Are they allowed in backend instances?
  2. In the backend servlet, flush the reply and close the writer() - nothing happens. Front end does not receive anything.

I tried all this on dev server. Should it be tried on production?

like image 571
Peter Knego Avatar asked Dec 16 '22 04:12

Peter Knego


1 Answers

The way to do long-running requests on AppEngine, on frontend or backend, is to use task queues. Tasks have a 10-minute timeout rather than 60 seconds, but if you need even more time you can run it on a backend instance by giving it a target name.

like image 163
Daniel Roseman Avatar answered May 13 '23 00:05

Daniel Roseman