取消谷歌应用引擎端点请求

时间:2021-06-06 20:20:19

Im currently using GAE from Android. I have a search operation which performs what might be a long running query on the datastore (called from 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).

我目前正在使用Android的GAE。我有一个搜索操作,它执行可能是数据存储区上长时间运行的查询(从AsyncTask调用)。用户可以选择在此过程仍在运行时从应用程序注销。如果没有取消此请求的选项,实际注销必须等到进程完成并且控制权返回到客户端(正如我所说,可能需要几秒钟)。

Is there a way to cancel a call to a GAE endpoint while the server is running and return the control to the client ? Thanks.

有没有办法在服务器运行时取消对GAE端点的调用并将控制权返回给客户端?谢谢。

p.s.
Obviously, cancelling the AsyncTask only is not enough.

附:显然,仅取消AsyncTask是不够的。

2 个解决方案

#1


0  

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?

就个人而言,我将服务器comm放在一个服务中,这样无论用户做什么,请求都可以(通常)完成。在您的情况下,您可以让用户注销,还可以让请求完成吗?

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) - 是不够的,是因为你已经尝试了它并且它不会中断被阻止的操作。

#2


0  

No, Google Endpoints use servlets and servlets have no (standard) way of telling a running request to cancel it's work. You will need to build something proprietary.

不,Google端点使用servlet和servlet没有(标准)方式告诉正在运行的请求取消它的工作。你需要建立专有的东西。

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.

例如:在服务器上长时间运行的进程中,您在其主循环中检查用户是否仍然登录(通过数据存储区或内存缓存中的标志)。如果此标志告诉您用户已注销,则取消处理并返回。登录/注销过程也必须适当地设置此标志。

#1


0  

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?

就个人而言,我将服务器comm放在一个服务中,这样无论用户做什么,请求都可以(通常)完成。在您的情况下,您可以让用户注销,还可以让请求完成吗?

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) - 是不够的,是因为你已经尝试了它并且它不会中断被阻止的操作。

#2


0  

No, Google Endpoints use servlets and servlets have no (standard) way of telling a running request to cancel it's work. You will need to build something proprietary.

不,Google端点使用servlet和servlet没有(标准)方式告诉正在运行的请求取消它的工作。你需要建立专有的东西。

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.

例如:在服务器上长时间运行的进程中,您在其主循环中检查用户是否仍然登录(通过数据存储区或内存缓存中的标志)。如果此标志告诉您用户已注销,则取消处理并返回。登录/注销过程也必须适当地设置此标志。