Я пытаюсь добиться сильной согласованности. Назовем мою модель PVPPlayer
:
class PVPPlayer(ndb.Model):
points = ndb.IntegerProperty()
Каждый ключ для модели создается следующим образом:
pvp_player = PVPPlayer(key=ndb.Key(Profile, "test_id", PVPPlayer, "test_id"))
где Profile
— родительская модель:
class Profile(ndb.Model):
def build_key(cls, some_id):
return ndb.Key(cls, some_id)
У меня есть 2 URL REST API:
1) update_points
2) get_points
In 1) I do :
# I use transaction because I have to update all the models in single batch
@ndb.transactional(xg=True, retries=3)
def some_func(points):
pvp_player = ndb.Key(Profile, "test_id", PVPPlayer, "test_id").get()
pvp_player.points += points
pvp_player.put()
# update other models here`
In 2) I do:
pvp_player = ndb.Key(Profile, "test_id", PVPPlayer, "test_id").get()
return pvp_player.points`
Мой поток выглядит так:
1) update_points()
2) get_points()
3) update_points()
4) get_points()`
...
Проблема:
Использование get()
гарантирует строгую согласованность, поэтому я не понимаю, почему иногда в результате get_points()
я получаю устаревшие данные, как будто точки вообще не обновлялись.
Пример:
POST get_points -> 0
POST sleep 1-3 sec
POST update_points -> 15
POST sleep 1-3 sec
POST get_points -> 15
POST sleep 1-3 sec
POST update_points -> 20
POST sleep 1-3 sec
POST get_points -> 15 !!!`
@ndb.transactional
? Кроме того, я предполагаю, что имя функцииupdate_points
в #1 на самом делеupdate_points
, верно? - person Dan Cornilescu   schedule 25.08.2016some_func
этоupdate_points
? :) - person Dan Cornilescu   schedule 25.08.2016