Re:I only know PHP. How do I write a Web application in Python?
by VBprogrammer on Sunday May 06, 2012 @03:27PM
(#3936037)
> Updating a customer's winnings and recording a win are definitely things that should be together in a transaction - if one happened and not the other, that's a failure.
Yes, they these clearly do belong in the same transaction. Inserting a congratulations email into the email queue doesn't.
Re:I only know PHP. How do I write a Web application in Python?
by zzzeek on Sunday May 06, 2012 @07:02PM
(#3936711)
emails typically get fired off as part of a post-commit hook. Pyramid's transaction manager has explicit support for this pattern - as you establish "emails" within your trans, the actual send operation is deferred til after the transaction proceeds.
Updating a customer's winnings and recording a win are definitely things that should be together in a transaction - if one happened and not the other, that's a failure.
This is not the fault of using a transaction, this is the fault of not working with what is essentially a distributed transaction. Since you are relying on a message against a third party, you need to build distribution into this system, which is challenging. You might contact the third party after you've completed the internal processing, and you might use two-phase semantics even such that you can "PREPARE TRANSACTION" the work you've done locally, (nearly) guaranteeing that a commit will proceed, then work with your external messaging, then commit locally.
background at http://en.wikipedia.org/wiki/Two-phase_commit_protocol