[ZODB-Dev] Automating retry management

Nitro nitro at dr-code.org
Tue May 11 11:13:50 EDT 2010


Am 11.05.2010, 17:08 Uhr, schrieb Nitro <nitro at dr-code.org>:

> Am 11.05.2010, 16:01 Uhr, schrieb Jim Fulton <jim at zope.com>:
>
>> This wouldn't work.  You would need to re-execute the suite
>> for each retry. It's not enough to just keep committing the same
>> transaction. (There are other details wrong with the code above,
>> but they are fixable.)  Python doesn't provide a way to keep
>> executing the suite.
>
> You are right.
>
> The only thing I could come up with was something like below, using a
> decorator instead of a context.
>
> -Matthias
>
> @doTransaction(count = 5)
> def storeData():
>     ... store data here ...
>
> def doTransaction(transaction = None, count = 3):
>      def decorator(func):
>          def do():
>              for i in range(1+count):
>                  try:
>                      func()
>                  except:
>                      transaction.abort()
>                      raise
>                  try:
>                      transaction.commit()
>                  except ConflictError:
>                      if i == count:
>                          raise
>                  else:
>                      return
>          return do

This should read return do(), i.e. the decorator should directly execute  
the storeData function.

All in all I think Benji's proposal looks better :-)

-Matthias


More information about the ZODB-Dev mailing list