App Engine: the right way to run a long-term task in Backend from the front?

I would like to run a long-running task on a Backend instance. This basic task will be launched by the front-end code (servlet) through an HTTP request. All of this is described in the docs and it works for me.

What bothers me is that the front instances have a limit on the request duration of 30 seconds (or is it now 60 seconds?). During this request, the front end will call a backend to run a long-running task. However, since this task lasts a long time, and the front part is waiting for its completion and the waiting time expires.

The question is how to make an HTTP request from the front end to run the long-term backend task so that the front end does not get a timeout and the backend continues to work?

I already tried:

  • Start a separate thread in the backend. My IDE (Idea) complains about this, saying that Thread is not allowed in the App Engine. Are they permitted in internal instances?
  • In the server servlet, discard the response and close writer () - nothing happens. The front end gets nothing.

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

+4
source share
1 answer

The way to make long requests to AppEngine, to the 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 the backend instance by giving it the target name.

+12
source

Source: https://habr.com/ru/post/1392376/


All Articles