App Engine:从前端开始在后端执行长时间运行任务的正确方法? [英] App Engine: correct way to start long running task in Backend from the front end?

查看:324
本文介绍了App Engine:从前端开始在后端执行长时间运行任务的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Backend实例上开始一个长时间运行的任务。该后端任务将由前端代码(servlet)通过HTTP请求启动。这些都是在文档中描述的,并且适用于我。

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.

我遇到的困难是前端实例的请求持续时间限制为30秒(或者现在是60秒吗?) 。在该请求期间,前端将调用后端来启动长时间运行的任务。但是,由于此任务长时间运行,并且前端正在等待它完成并超时。

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.

问题是如何从前端发出HTTP请求来启动长时间运行的后端任务,以便前端不会超时,后端将继续运行?

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. 开始一个单独的线程后端。我的IDE(Idea)对此抱怨,说App Engine上不允许线程。它们是否允许在后端实例中?

  2. 在后端servlet中,刷新回复并关闭writer() - 没有任何反应。前端没有收到任何东西。

我在开发服务器上尝试了这一切。应该在生产环境中尝试吗?

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

推荐答案

在AppEngine前端或后端执行长时间运行的请求的方法是使用任务队列。任务有10分钟超时而不是60秒,但是如果您需要更多时间,可以通过给它一个目标名称在后端实例上运行它。

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.

这篇关于App Engine:从前端开始在后端执行长时间运行任务的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆