google app engine - GAE Python NDB .put not synchronous on development (but works in production)? -
the following below should create counter model , use (deferred) tasks increment counter 10. visiting '/' ought create single counter object count = 10. happens in production. in development (localhost) multiple counter objects created largest being 10:

i suspect because put not synchronous on development (but appears on production). there way make them synchronous?
code snippet below:
class counter(ndb.model): count = ndb.integerproperty(indexed=false) def reset(): ndb.delete_multi(counter().query().fetch(keys_only=true, use_cache=false, use_memcache=false)) def increment(): counter = counter().query().get(use_cache=false, use_memcache=false) if not counter: counter = counter(count=0) counter.count += 1 counter.put() if counter.count < 10: deferred.defer(increment) @app.route('/') def hello(): """return friendly http greeting.""" reset() deferred.defer(increment) return 'hello world!' i have git repo reproduces behavior here. can find commit makes last change here.
the production 'synchronicity' apparent, it's not guaranteed (in approach). can happen newly created counter not found in query, code create multiple counters.
more details in balancing strong , eventual consistency google cloud datastore article.
Comments
Post a Comment