简体   繁体   English

取消Google App Engine端点请求

[英]Cancelling a google app engine endpoint request

Im currently using GAE from Android. 我目前正在从Android使用GAE。 I have a search operation which performs what might be a long running query on the datastore (called from AsyncTask). 我有一个搜索操作,该操作对数据存储区执行长时间运行的查询(从AsyncTask调用)。 The user has an option to logout from the app while this process is still running. 在此过程仍在运行时,用户可以选择从应用程序注销。 Without an option to cancel this request the actual logout has to wait until the process finishes and the control is back to the client (which, as i said, can take a few seconds). 如果没有取消该请求的选项,则实际注销必须等待该过程完成,并且控制权将返回给客户端(如我所说,这可能需要几秒钟)。

Is there a way to cancel a call to a GAE endpoint while the server is running and return the control to the client ? 有没有办法在服务器运行时取消对GAE端点的调用,然后将控制权返回给客户端? Thanks. 谢谢。

ps ps
Obviously, cancelling the AsyncTask only is not enough. 显然,仅取消AsyncTask是不够的。

Personally, I put the server comm in a service so that requests can (usually) finish regardless of what the user does. 就个人而言,我将服务器通讯置于服务中,以便无论用户做什么都可以(通常)完成请求。 In your case, could you let the user log out, but also let the request complete? 就您而言,您可以让用户注销,也可以让请求完成吗?

Otherwise, I don't know how to cleanly interrupt an endpoint request. 否则,我不知道如何彻底中断端点请求。 Unfortunately, the actual blocking operation is buried in the endpoints (Google API Client library) code and no cancel operation is exposed that I'm aware of. 不幸的是,实际的阻止操作被掩埋在端点(Google API客户端库)代码中,并且我没有意识到没有取消操作。

When you write that cancelling the task - AsyncTask.cancel(boolean mayInterruptIfRunning) - is not enough, is that because you've tried it and it doesn't interrupt a blocked operation. 当您编写该取消任务的信息时-AsyncTask.cancel(boolean mayInterruptIfRunning)-是不够的,这是因为您已经尝试过了,并且它不会中断被阻止的操作。

No, Google Endpoints use servlets and servlets have no (standard) way of telling a running request to cancel it's work. 不,Google Endpoints使用servlet,并且servlet没有(标准)告诉运行中的请求取消其工作的方法。 You will need to build something proprietary. 您将需要构建一些专有的东西。

For example: in your long-running process on server you in it's main loop check if user is still logged in (via a flag in the datastore or memcache). 例如:在服务器上长时间运行的进程中,在主循环中检查用户是否仍在登录(通过数据存储区或内存缓存中的标志)。 If this flag tells you that user is logged out, then you cancel the processing and return. 如果此标志告诉您该用户已注销,则您取消处理并返回。 Also a login/logout procedure must appropriately set this flag. 另外,登录/注销过程必须适当设置此标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM