Understanding “CancellationException: Task was cancelled” error while doing a Google Datastore query

孤者浪人 提交于 2019-12-02 03:52:10
  1. You don't need to call .list().size(), you can simply call count().

  2. If you simply count, use a keys-only query - it's free and much faster.

  3. Don't forget to set chunckAll() on your query when you expect to process a large number of entities. It's much faster than a default setting.

If you still run into these exceptions, you need to use cursors in your query.

Such error occurrs due to following common reasons:

  1. Any API call like datastore.list times out
    Solution: read data in paged manner via cursor

  2. Parent method hits the request time out limit e.g. cronjob hits 10 mins limit in standard app engine Solution: Increase time out or use multi-threading or use cache to expedite the execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!