[ZODB-Dev] transaction "Attempts" class

Chris McDonough chrism at plope.com
Wed Mar 28 20:37:49 UTC 2012


On Wed, 2012-03-28 at 14:21 -0400, Jim Fulton wrote:
> On Wed, Mar 28, 2012 at 2:11 PM, Zvezdan Petkovic <zvezdan at computer.org> wrote:
> ...
> 
> Thanks for chiming in Zvezdan. I was hoping you would. :)
> 
> We should fix this if we can. If I could do over, I'd have a different
> API that uses a function rather than a block and was designed to work
> as a decorator.  Something like:
> 
> @transaction.job
> def doit(tx):
>        ...
> 
> where doit would, hopefully, be descriptive.
> 
> You's also be able to:
> 
> @transaction.job(retry_limit=5)
> def doit(tx):
>        ...
> 
> As a bonus, I'd automatically set a transaction note with the function
> name or first line of doc string, and the retry #.
> 
> I do plan to do this, um, when I get around to it.  Might be a nice
> small project for someone who wants to contribute.
> 
> The with statement is really wanting when you might want to execute
> code other than once.

A decorator for running some code in the context of a txn and retrying
retryable exceptions would be nice higher level behavior.  I'd be
willing to do this work over this weekend.

In the meantime, I think the existing attempts context manager still
needs the small fix I proposed in my original message.  Can you confirm
that my understanding of the its intent seems roughly correct?

- C




More information about the ZODB-Dev mailing list