Google App Engine: (Python) Datastore transactions

2019-09-04 09:34发布

I'd like some help understanding transactions and indempotence.

Note: If your app receives an exception when submitting a transaction, it does not always mean that the transaction failed. You can receive Timeout, TransactionFailedError, or InternalError exceptions in cases where transactions have been committed and eventually will be applied successfully. Whenever possible, make your Datastore transactions idempotent so that if you repeat a transaction, the end result will be the same.

I have a game where players receive an email when something special happens. There is a bug were players sometimes receive 2 (or more) emails. I believe its because I am processing the game rules inside a transaction, but sending of emails outside.

some pseudocode:

def game_update(orders_from_player):
  emails_to_send = db.run_in_transaction(process_player_orders, orders_from_player)
  for e in emails_to_send:
    send_email(e)

Is it true to say that, upon a transaction collision I should expect the list of emails to be sent out again?

Is the whole request repeated, or just the call to the transactional procedure.(in this case process_player_orders)

I'm confused.

0条回答
登录 后发表回答