2011-09-17 9 views
10

タスク内では、クエリを持つアイテムのコレクションを繰り返し処理しています。クエリから各エンティティを取得した後、URLリクエストも実行しています。これらの多数の項目を反復処理した後、私は次のエラーを見ている:あなたはそれを作成した後期限切れのクエリとAppengine

BadRequestError: The requested query has expired. Please restart it with the last cursor to read more results. 

は、クエリのリースは何ですか?

答えて

7

この問題は、あなたの問題にいくつかの光を当てることがありますhttps://code.google.com/p/googleappengine/issues/detail?id=4432

Even though offline requests can currently live up to 10 minutes (and background instances can live forever) datastore queries can still only live for 30 seconds. We plan to improve this, but since a 'consistent' view of the data is only preserved for a limit period of time, there is an upper bound to how long a query can last (which is < 10 minutes).

...

Instead of running a single long query, consider fetching batches from the query using query cursors.

0

シンプルで、あなたのシーケンスの各要素に対してdeferedタスクを作成します。適切な方法でそれを行う方法の例がある良い記事 "Background work with the deferred library"があります。

1

私はこれを行うための簡単なヘルパーを書いています。これは、batch_size、クエリのオブジェクトクラス、およびクエリの要素を処理するコールバックで呼び出すことができます。

(注、私はdjangoappengineので、Djangoのクエリ形式を使用しています - しかし、あなたが合うように、それを変更することができます。)(カウント)と明示的に残りをうまくする必要が

def loop_over_objects_in_batches(batch_size, object_class, callback): 
    logging.info("Calling batched loop with batch_size: %d, object_class: %s, callback: %s" % (batch_size, object_class, callback)) 

    num_els = object_class.objects.all().count() 
    num_loops = num_els/batch_size 
    remainder = num_els - num_loops * batch_size 
    offset = 0 
    while offset < num_loops * batch_size: 
     logging.info("Processing batch (%d:%d)" % (offset, offset+batch_size)) 
     query = object_class.objects.all()[offset:offset + batch_size] 
     for q in query: 
      callback(q) 

     offset = offset + batch_size 

    if remainder: 
     logging.info("Processing remainder batch (%d:-)" % offset) 
     query = object_class.objects.all()[offset:] 
     for q in query: 
      callback(q) 
+0

ありませんでした - [: ]スライスは残りのクエリを返します。ループ内でそれを検出して、それを突き止めることができます。私はこれを明確に書いて、私がやっていることを明確にしています。 –

関連する問題