Skip to content

Instantly share code, notes, and snippets.

@jdiaz5513
Created February 10, 2014 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdiaz5513/8911930 to your computer and use it in GitHub Desktop.
Save jdiaz5513/8911930 to your computer and use it in GitHub Desktop.
mapreduce.operations.ndb - helper for Google App Engine MapReduce NDB operations
"""NDB-related operations."""
__all__ = ['Put', 'Delete']
from mapreduce.operation import base
# pylint: disable=protected-access
class Put(base.Operation):
"""Put entity into datastore via mutation_pool.
See mapreduce.context._MutationPool.
"""
def __init__(self, entity):
"""Constructor.
Args:
entity: an entity to put.
"""
self.entity = entity
def __call__(self, context):
"""Perform operation.
Args:
context: mapreduce context as context.Context.
"""
context._mutation_pool.ndb_put(self.entity)
class Delete(base.Operation):
"""Delete entity from datastore via mutation_pool.
See mapreduce.context._MutationPool.
"""
def __init__(self, entity):
"""Constructor.
Args:
entity: a key or model instance to delete.
"""
self.entity = entity
def __call__(self, context):
"""Perform operation.
Args:
context: mapreduce context as context.Context.
"""
context._mutation_pool.ndb_delete(self.entity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment