Objectify多个过滤器不能与cron作业一起使用 [英] Objectify multiple filters doesn´t work with cron job

查看:265
本文介绍了Objectify多个过滤器不能与cron作业一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在appengine上使用objectify,我试图添加一个cron作业以删除所有超过一小时的临时实体:

I´m working with objectify on appengine, I tried to add a cron job to delete all temp entities which are older than an hour:

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作业时遇到异常:

but i always get an Exception when executing the cron job on the appengine server:

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>

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

does anybody know why this happens? The job works if I remove:

.filter("createdAt", oneHourAgo)


推荐答案

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

When you use your app with a Development server, the development server tries to figure out which indexes you need and places them in the index-definition file automatically. Since you use this query in a cron job, the development server cannot help you here. You will need to add a definition for this index manually.

Java数据存储区索引配置

这篇关于Objectify多个过滤器不能与cron作业一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆