App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | List of all members
google.appengine.ext.ndb.context.AutoBatcher Class Reference
Inheritance diagram for google.appengine.ext.ndb.context.AutoBatcher:

Public Member Functions

def __init__
 
def __repr__
 
def run_queue
 
def add
 
def add_once
 
def action
 
def flush
 

Detailed Description

Batches multiple async calls if they share the same rpc options.

Here is an example to explain what this class does.

Life of a key.get_async(options) API call:
*) Key gets the singleton Context instance and invokes Context.get.
*) Context.get calls Context._get_batcher.add(key, options). This
   returns a future "fut" as the return value of key.get_async.
   At this moment, key.get_async returns.

*) When more than "limit" number of _get_batcher.add() was called,
   _get_batcher invokes its self._todo_tasklet, Context._get_tasklet,
   with the list of keys seen so far.
*) Context._get_tasklet fires a MultiRPC and waits on it.
*) Upon MultiRPC completion, Context._get_tasklet passes on the results
   to the respective "fut" from key.get_async.

*) If user calls "fut".get_result() before "limit" number of add() was called,
   "fut".get_result() will repeatedly call eventloop.run1().
*) After processing immediate callbacks, eventloop will run idlers.
   AutoBatcher._on_idle is an idler.
*) _on_idle will run the "todo_tasklet" before the batch is full.

So the engine is todo_tasklet, which is a proxy tasklet that can combine
arguments into batches and passes along results back to respective futures.
This class is mainly a helper that invokes todo_tasklet with the right
arguments at the right time.

Constructor & Destructor Documentation

def google.appengine.ext.ndb.context.AutoBatcher.__init__ (   self,
  todo_tasklet,
  limit 
)
Init.

Args:
  todo_tasklet: the tasklet that actually fires RPC and waits on a MultiRPC.
It should take a list of (future, arg) pairs and an "options" as
arguments. "options" are rpc options.
  limit: max number of items to batch for each distinct value of "options".

Member Function Documentation

def google.appengine.ext.ndb.context.AutoBatcher.add (   self,
  arg,
  options = None 
)
Adds an arg and gets back a future.

Args:
  arg: one argument for _todo_tasklet.
  options: rpc options.

Return:
  An instance of future, representing the result of running
_todo_tasklet without batching.
def google.appengine.ext.ndb.context.AutoBatcher.run_queue (   self,
  options,
  todo 
)
Actually run the _todo_tasklet.

The documentation for this class was generated from the following file: