Hey Jeff,
  That is more-or-less the best I've come up with as well.  My flow looks like:
  1) produce a transaction marker entity with a deterministic key-name
from the involved "accounts",
  2) Start transaction:
    2.a) Load the involved entities (including the marker).
    2.b) If I get a marker, abort.
    2.c) Do the stuff that needs doing....
  3) At some later (possibly much later) time, cleanup the markers.

  In some cases, when I've got revision numbers on the entities, I
improve the process by cleaning the marker up after the transaction.
But if it is valid for an account to be updated multiple times,
provided some condition is met, I leave the marker.  Note that nearly
all of my processing is task-based, so tasks could run multiple times,
or rerun with a delay, etc....  That is why I leave the markers for a
while.


Robert


On Fri, Jan 20, 2012 at 00:22, Jeff Schnitzer <[email protected]> wrote:
> I'd like to guarantee a transaction runs once, and once only.  Let's
> say I'm simulating a bank transfer of $5 from AccountA to AccountB.
>
> The normal transaction is not idempotent:
>
> Repeat until success {
>  * start txn
>  * debit $5 from AccountA
>  * credit $5 to AccountB
>  * commit txn
> }
>
> If this inadvertently runs multiple times, I will have very unhappy
> customers.  Maybe I should do this:
>
> Create TxnID entity instance
> Repeat until success {
>  * start txn
>  * load TxnID (if null, return success immediately)
>  * debit $5 from AccountA
>  * credit $5 to AccountB
>  * delete TxnID
>  * commit txn
> }
>
> With the pain of adding a third entity to my XG transaction (and a
> cron that prunes really old, abandoned TxnIDs) it seems that I this
> does the trick.  Or am I missing something?  Is this the best way to
> accomplish once-only transactions?  Is there an alternative approach?
>
> Thanks in advance,
> Jeff
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to