Re: query about after commit hook

Jim Fulton <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <CAPDm-Fid+__15+xM0=seOpqWc+GegED0Vqp8=QMGpYJLHcJmfw@mail.gmail.com>
On Fri, May 20, 2016 at 11:23 AM, Jason Madden
<[email protected]> wrote:
> 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.

This is an approach (Faux IDatamanager's) that I advocated early on.
I regret it now.  Sometimes I was too Zealously OO.

I regret it because: a) It was a pain to implement, and b) still a bit
of a trap. :)

BTW, I think it would be better to run the non-transactional data
manager first, so that if it fails, it doesn't leave transactional
data managers in a finished state. (The transaction module doesn't
freak out if the first data manager fails in the second phase of
2-phase commit.)

I think a mid-transaction hook would be much simpler, as I suggested
in another message, although it has downsides, as I also mentioned.


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

Yeah, another reason I don't like it.

>
> - `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`.

But it requires much care.

Jim

-- 
Jim Fulton
http://jimfulton.info

-- 
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.