Created
February 10, 2014 07:48
-
-
Save jdiaz5513/8911930 to your computer and use it in GitHub Desktop.
mapreduce.operations.ndb - helper for Google App Engine MapReduce NDB operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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