Objectify multiple filters doesn´t work with cron job

被刻印的时光 ゝ 提交于 2019-12-25 07:16:44

问题


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);
}

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)

回答1:


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 Datastore Index Configuration



来源:https://stackoverflow.com/questions/25547895/objectify-multiple-filters-doesn%c2%b4t-work-with-cron-job

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