View source on GitHub
|
Batches multiple async calls if they share the same RPC options.
Inherits From: expected_type
google.appengine.ext.ndb.AutoBatcher(
todo_tasklet, limit
)
Here is an example to explain what this class does.
Life of a key.get_async(options) API call:
Keygets the singletonContextinstance and invokesContext.get.Context.getcallsContext._get_batcher.add(key, options). This returns a futurefutas the return value ofkey.get_async. At this moment,key.get_asyncreturns.When more than "limit" number of
_get_batcher.add()was called,_get_batcherinvokes itsself._todo_tasklet,Context._get_tasklet, with the list of keys seen so far.Context._get_taskletfires a MultiRPC and waits on it.Upon MultiRPC completion,
Context._get_taskletpasses on the results to the respectivefutfromkey.get_async.If user calls
fut.get_result()before "limit" number ofadd()was called,fut.get_result()will repeatedly calleventloop.run1().After processing immediate callbacks,
eventloopwill run idlers.AutoBatcher._on_idleis an idler._on_idlewill run thetodo_taskletbefore 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.
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". |
Methods
action
action()
add
add(
arg, options=None
)
Returns back an instance of future after adding an arg.
| Args | |
|---|---|
arg
|
One argument for _todo_tasklet.
|
options
|
RPC options. |
| Return | |
|---|---|
An instance of future, representing the result of running
_todo_tasklet without batching.
|
add_once
add_once(
arg, options=None
)
flush
flush()
run_queue
run_queue(
options, todo
)
Actually run the _todo_tasklet.
View source on GitHub