Re: query about after commit hook

Jason Madden <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>
I sometimes do things like that (for example, updating redis) using a IDataManager joined to the transaction with a sortKey() that places it at the end. Most of the work (for redis) happens in its `tpc_finish` method, but it is kept apprised of the state of the transaction, and has the opportunity to veto it or do preflight checks to see if the operation is likely to succeed. 

- `tpc_finish` has to catch and swallow exceptions, but that happens with after commit hooks anyway. 

- `tpc_finish` is only called when the rest of the transaction phases for all the resource managers succeeded and everything is committed, which is different than an after commit hook (which gets a bool for the state of the transaction).

- This can work well for writing to the filesystem, where you can write a temp file in `tpc_begin`, and only do the final renaming in `tpc_finish`, making things a tiny bit safer. `repoze.sendmail` does something like this for its maildir-based `QueuedMailDelivery`.

> On May 20, 2016, at 03:01, Thierry Florac <[email protected]> wrote:
> 
> Hi,
> I often use "after commit hooks" to handle actions which are not "transaction aware" (for example, to do an update on a file system or on a remote server).
> If I want to make these updates only if my transaction is committed, how can I do it without using these hooks ?
> 
> Best regards,
> Thierry
> 
> 2016-05-20 9:16 GMT+02:00 Sanjay Rao <[email protected]>:
> IMO, after commit hooks are largely bug magnets that should be ignored 
> by almost all users. 
> 
> Do you mean that we should not use "after-commit-hook" ???
> 
> 
> On Thursday, 19 May 2016 18:03:31 UTC+5:30, Sanjay Rao wrote:
> Hi,
> 
> Is this flow correct ?
> 
> - Begin a new transaction
> - Run a method (method1). method1 registers method2 as after-commit-hook
> - Commit transaction
> - method2 is called
> - method2 raises exception
> - begin a new transaction
> - Call method3 and commit transaction
> 
> 
> Regards,
> Sanjay Rao
> 
> -- 
> You received this message because you are subscribed to the Google Groups "zodb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> http://www.imagesdusport.com -- http://www.ztfy.org
> 
> -- 
> You received this message because you are subscribed to the Google Groups "zodb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.