java - 对象化多个过滤器不适用于 cron 作业

标签 java google-app-engine cron objectify

我正在 appengine 上使用 objectify,我尝试添加一个 cron 作业来删除所有早于一小时的临时实体:

Iterable<Key<Entry>> allKeys = ofy().load().type(Entry.class)
                                    .filter("temporary", true)
                                    .filter("createdAt", oneHourAgo).keys();
if(allKeys != null){
  ofy().delete().keys(allKeys);
}

但在 appengine 服务器上执行 cron 作业时我总是遇到异常:

com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
    <datastore-index kind="Entry" ancestor="false" source="manual">
        <property name="temporary" direction="asc"/>
        <property name="createdAt" direction="asc"/>
    </datastore-index>

有人知道为什么会发生这种情况吗?如果我删除,这项工作就可以进行:

.filter("createdAt", oneHourAgo)

最佳答案

当您将应用程序与开发服务器一起使用时,开发服务器会尝试找出您需要的索引并自动将它们放入索引定义文件中。由于您在 cron 作业中使用此查询,因此开发服务器无法在此为您提供帮助。您需要手动添加此索引的定义。

Java Datastore Index Configuration

关于java - 对象化多个过滤器不适用于 cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25547895/

相关文章:

javascript - pm2 cron 在启动时自动运行

Cron 运行 rake 任务 "could not find rake-0.8.7 in any of the sources"

jquery - 想要使用 jquery 在 html 页面上有一个具有排序、搜索、分页功能的显示表

google-app-engine - 应用程序错误: Bad response: 404 Not Found (not 200 OK

java - GAE 索引(再次)

java - 如何计算多线程应用程序中的总执行时间

ruby-on-rails - 在Heroku上每分钟安排一次Rails 3.1

java - Spring MVC 中的 session

java - 在网络应用程序(war)中,我有一个配置文本文件。如何阻止网络访问呢?

java - 热至 "flatten"TornadoFX(JavaFX 扩展)中 ObjectProperty 的 ObjectProperty?