如何在谷歌应用程序引擎中将后台任务带到前台?
目前我有任务在后台运行。任务执行完成后,我需要显示输出。如何在 Google App Engine 中执行此操作?
任务完成后,我唯一能做的就是创建另一个应该显示输出的任务,或者还有其他方法吗?
Currently I have tasks running in background. After the tasks are done executing I need to show output. How do I do this in Google App Engine?
Once the tasks are done the only thing I can do is create another task which is supposed to show output or is there any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能“将任务带到前台”——它是一个网络服务器。服务器响应来自客户端的请求。
但是,您有多种选择可以完成类似的任务:
You can't "bring a task to the foreground" -- it is a webserver. The server responds to requests from the client.
But, you have a couple choices to accomplish something similar:
这不会像您所描述的那样直接起作用。
一旦后台任务启动,它就一直是后台任务。如果您想从后台任务返回一些信息给用户,您必须将其添加到数据存储中,并让前台处理程序检查数据存储中的该信息。
您也许还可以使用 Channel API 让后台任务直接向浏览器发送消息,但我不确定这是否有效(我还没有尝试过)。
如果您提供更多有关您想要完成的任务的更多信息,我可以尝试提供有关如何完成它的更多详细信息。
This won't work directly as you describe it.
Once a background task is started, it's a background task for its entire existence. If you want to return some information from the background task to the user, you'll have to add it to the datastore, and have a foreground handler check the datastore for that information.
You may also be able to use the Channel API to have a background task send messages directly to the browser, but I'm not sure if this will work or not (I haven't tried it).
If you give a little more information about exactly what you're trying to accomplish I can try to give more details about how to get it done.