I need to update a number of instances of class Foo on Google App Engine Datastore using ndb.
Here's what I have so far:
while more:
foo_instances, more_cursor, more = Foo.query().fetch_page(
20, start_cursor=more_cursor)
for foo in foo_instances:
bar = foo.bar.get() # foo.bar is a Key to a Bar instance.
bar.updated = True
ndb.put_multi(foo_instances)
and (tasklet friendly):
foo_iterator = Foo.query().iter()
while (yield foo_iterator.has_next_async()):
foo = foo_iterator.next()
bar = foo.bar.get() # foo.bar is a Key to a Bar instance.
bar.updated = True
yield bar.put_async()
I'm planning to execute this code in a Push Queue task which I believe to have a 10 minute window before timing out.
Which one is the correct approach (if any) to execute the task and avoid timeout or memory issues? There are a few thousands of instances of type Foo.